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

Kernel: Allow Lock to block from BlockCondition

This enables the Lock class to block a thread even while the thread is
working on a BlockCondition. A thread can still only be either blocked
by a Lock or a BlockCondition.

This also establishes a linked list of threads that are blocked by a
Lock and unblocking directly unlocks threads and wakes them directly.
This commit is contained in:
Tom 2021-07-10 10:23:16 -06:00 committed by Andreas Kling
parent d9fb93c5ce
commit 026ffa343d
8 changed files with 442 additions and 267 deletions

View file

@ -116,6 +116,7 @@ class Thread
AK_MAKE_NONCOPYABLE(Thread);
AK_MAKE_NONMOVABLE(Thread);
friend class Lock;
friend class Process;
friend class ProtectedProcessBase;
friend class Scheduler;
@ -823,6 +824,8 @@ public:
}
}
void block(Kernel::Lock&, ScopedSpinLock<SpinLock<u8>>&, u32);
template<typename BlockerType, class... Args>
[[nodiscard]] BlockResult block(const BlockTimeout& timeout, Args&&... args)
{
@ -954,6 +957,7 @@ public:
return result;
}
u32 unblock_from_lock(Kernel::Lock&);
void unblock_from_blocker(Blocker&);
void unblock(u8 signal = 0);
@ -1280,6 +1284,9 @@ private:
Optional<Range> m_thread_specific_range;
Array<SignalActionData, NSIG> m_signal_action_data;
Blocker* m_blocker { nullptr };
Kernel::Lock* m_blocking_lock { nullptr };
u32 m_lock_requested_count { 0 };
IntrusiveListNode<Thread> m_blocked_threads_list_node;
bool m_may_die_immediately { true };
#if LOCK_DEBUG