mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 04:20:28 +00:00
Kernel: Don't register thread as custom data for FutexBlocker
Same deal as WaitQueueBlocker, we can get the blocked thread from Blocker::thread() now, so there's no need to register the current thread as custom data.
This commit is contained in:
parent
2c74533ba6
commit
b012170d69
Notes:
sideshowbarker
2024-07-18 05:19:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b012170d69c
3 changed files with 11 additions and 15 deletions
|
@ -18,9 +18,8 @@ FutexQueue::~FutexQueue()
|
|||
{
|
||||
}
|
||||
|
||||
bool FutexQueue::should_add_blocker(Thread::Blocker& b, void* data)
|
||||
bool FutexQueue::should_add_blocker(Thread::Blocker& b, void*)
|
||||
{
|
||||
VERIFY(data != nullptr); // Thread that is requesting to be blocked
|
||||
VERIFY(m_lock.is_locked());
|
||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Futex);
|
||||
|
||||
|
@ -28,10 +27,10 @@ bool FutexQueue::should_add_blocker(Thread::Blocker& b, void* data)
|
|||
m_imminent_waits--;
|
||||
|
||||
if (m_was_removed) {
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: should not block thread {}: was removed", this, *static_cast<Thread*>(data));
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: should not block thread {}: was removed", this, b.thread());
|
||||
return false;
|
||||
}
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: should block thread {}", this, *static_cast<Thread*>(data));
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: should block thread {}", this, b.thread());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -44,12 +43,11 @@ u32 FutexQueue::wake_n_requeue(u32 wake_count, const Function<FutexQueue*()>& ge
|
|||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_n_requeue({}, {})", this, wake_count, requeue_count);
|
||||
|
||||
u32 did_wake = 0, did_requeue = 0;
|
||||
unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) {
|
||||
VERIFY(data);
|
||||
unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool& stop_iterating) {
|
||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Futex);
|
||||
auto& blocker = static_cast<Thread::FutexBlocker&>(b);
|
||||
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_n_requeue unblocking {}", this, *static_cast<Thread*>(data));
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_n_requeue unblocking {}", this, blocker.thread());
|
||||
VERIFY(did_wake < wake_count);
|
||||
if (blocker.unblock()) {
|
||||
if (++did_wake >= wake_count)
|
||||
|
@ -103,12 +101,11 @@ u32 FutexQueue::wake_n(u32 wake_count, const Optional<u32>& bitset, bool& is_emp
|
|||
SpinlockLocker lock(m_lock);
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_n({})", this, wake_count);
|
||||
u32 did_wake = 0;
|
||||
unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool& stop_iterating) {
|
||||
VERIFY(data);
|
||||
unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool& stop_iterating) {
|
||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Futex);
|
||||
auto& blocker = static_cast<Thread::FutexBlocker&>(b);
|
||||
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_n unblocking {}", this, *static_cast<Thread*>(data));
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_n unblocking {}", this, blocker.thread());
|
||||
VERIFY(did_wake < wake_count);
|
||||
if (bitset.has_value() ? blocker.unblock_bitset(bitset.value()) : blocker.unblock()) {
|
||||
if (++did_wake >= wake_count)
|
||||
|
@ -126,11 +123,10 @@ u32 FutexQueue::wake_all(bool& is_empty)
|
|||
SpinlockLocker lock(m_lock);
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_all", this);
|
||||
u32 did_wake = 0;
|
||||
unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void* data, bool&) {
|
||||
VERIFY(data);
|
||||
unblock_all_blockers_whose_conditions_are_met_locked([&](Thread::Blocker& b, void*, bool&) {
|
||||
VERIFY(b.blocker_type() == Thread::Blocker::Type::Futex);
|
||||
auto& blocker = static_cast<Thread::FutexBlocker&>(b);
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_all unblocking {}", this, *static_cast<Thread*>(data));
|
||||
dbgln_if(FUTEXQUEUE_DEBUG, "FutexQueue @ {}: wake_all unblocking {}", this, blocker.thread());
|
||||
if (blocker.unblock(true)) {
|
||||
did_wake++;
|
||||
return true;
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
bool is_empty_and_no_imminent_waits_locked();
|
||||
|
||||
protected:
|
||||
virtual bool should_add_blocker(Thread::Blocker& b, void* data) override;
|
||||
virtual bool should_add_blocker(Thread::Blocker& b, void*) override;
|
||||
|
||||
private:
|
||||
size_t m_imminent_waits { 1 }; // We only create this object if we're going to be waiting, so start out with 1
|
||||
|
|
|
@ -140,7 +140,7 @@ bool Thread::WaitQueueBlocker::unblock()
|
|||
Thread::FutexBlocker::FutexBlocker(FutexQueue& futex_queue, u32 bitset)
|
||||
: m_bitset(bitset)
|
||||
{
|
||||
if (!add_to_blocker_set(futex_queue, Thread::current()))
|
||||
if (!add_to_blocker_set(futex_queue))
|
||||
m_should_block = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue