1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

Kernel: Some futex improvements

This adds support for FUTEX_WAKE_OP, FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET,
FUTEX_REQUEUE, and FUTEX_CMP_REQUEUE, as well well as global and private
futex and absolute/relative timeouts against the appropriate clock. This
also changes the implementation so that kernel resources are only used when
a thread is blocked on a futex.

Global futexes are implemented as offsets in VMObjects, so that different
processes can share a futex against the same VMObject despite potentially
being mapped at different virtual addresses.
This commit is contained in:
Tom 2020-12-21 23:21:58 -07:00 committed by Andreas Kling
parent 7581b64705
commit 1d621ab172
23 changed files with 928 additions and 63 deletions

View file

@ -148,6 +148,52 @@ bool Thread::QueueBlocker::unblock()
return true;
}
Thread::FutexBlocker::FutexBlocker(FutexQueue& futex_queue, u32 bitset)
: m_bitset(bitset)
{
if (!set_block_condition(futex_queue, Thread::current()))
m_should_block = false;
}
Thread::FutexBlocker::~FutexBlocker()
{
}
void Thread::FutexBlocker::finish_requeue(FutexQueue& futex_queue)
{
ASSERT(m_lock.own_lock());
set_block_condition_raw_locked(&futex_queue);
// We can now releas the lock
m_lock.unlock(m_relock_flags);
}
bool Thread::FutexBlocker::unblock_bitset(u32 bitset)
{
{
ScopedSpinLock lock(m_lock);
if (m_did_unblock || (bitset != FUTEX_BITSET_MATCH_ANY && (m_bitset & bitset) == 0))
return false;
m_did_unblock = true;
}
unblock_from_blocker();
return true;
}
bool Thread::FutexBlocker::unblock(bool force)
{
{
ScopedSpinLock lock(m_lock);
if (m_did_unblock)
return force;
m_did_unblock = true;
}
unblock_from_blocker();
return true;
}
Thread::FileDescriptionBlocker::FileDescriptionBlocker(FileDescription& description, BlockFlags flags, BlockFlags& unblocked_flags)
: m_blocked_description(description)
, m_flags(flags)