1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 07:24:58 +00:00

Kernel: Stop using *LockRefPtr for Thread

These were stored in a bunch of places. The main one that's a bit iffy
is the Mutex::m_holder one, which I'm going to simplify in a subsequent
commit.

In Plan9FS and WorkQueue, we can't make the NNRPs const due to
initialization order problems. That's probably doable with further
cleanup, but left as an exercise for our future selves.

Before starting this, I expected the thread blockers to be a problem,
but as it turns out they were super straightforward (for once!) as they
don't mutate the thread after initiating a block, so they can just use
simple const-ified NNRPs.
This commit is contained in:
Andreas Kling 2023-04-02 20:40:47 +02:00
parent a098266ff5
commit c3915e4058
9 changed files with 26 additions and 30 deletions

View file

@ -329,7 +329,7 @@ Process::Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials> credent
}
}
ErrorOr<NonnullLockRefPtr<Thread>> Process::attach_resources(NonnullOwnPtr<Memory::AddressSpace>&& preallocated_space, Process* fork_parent)
ErrorOr<NonnullRefPtr<Thread>> Process::attach_resources(NonnullOwnPtr<Memory::AddressSpace>&& preallocated_space, Process* fork_parent)
{
m_space.with([&](auto& space) {
space = move(preallocated_space);
@ -338,10 +338,10 @@ ErrorOr<NonnullLockRefPtr<Thread>> Process::attach_resources(NonnullOwnPtr<Memor
auto create_first_thread = [&] {
if (fork_parent) {
// NOTE: fork() doesn't clone all threads; the thread that called fork() becomes the only thread in the new process.
return Thread::current()->try_clone(*this);
return Thread::current()->clone(*this);
}
// NOTE: This non-forked code path is only taken when the kernel creates a process "manually" (at boot.)
return Thread::try_create(*this);
return Thread::create(*this);
};
auto first_thread = TRY(create_first_thread());
@ -906,17 +906,13 @@ ErrorOr<void> Process::send_signal(u8 signal, Process* sender)
return ESRCH;
}
LockRefPtr<Thread> Process::create_kernel_thread(void (*entry)(void*), void* entry_data, u32 priority, NonnullOwnPtr<KString> name, u32 affinity, bool joinable)
ErrorOr<NonnullRefPtr<Thread>> Process::create_kernel_thread(void (*entry)(void*), void* entry_data, u32 priority, NonnullOwnPtr<KString> name, u32 affinity, bool joinable)
{
VERIFY((priority >= THREAD_PRIORITY_MIN) && (priority <= THREAD_PRIORITY_MAX));
// FIXME: Do something with guard pages?
auto thread_or_error = Thread::try_create(*this);
if (thread_or_error.is_error())
return {};
auto thread = thread_or_error.release_value();
auto thread = TRY(Thread::create(*this));
thread->set_name(move(name));
thread->set_affinity(affinity);
thread->set_priority(priority);