1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:47:44 +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

@ -26,6 +26,7 @@
#pragma once
#include <AK/HashTable.h>
#include <AK/InlineLinkedList.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
@ -38,6 +39,12 @@ namespace Kernel {
class Inode;
class PhysicalPage;
class VMObjectDeletedHandler {
public:
virtual ~VMObjectDeletedHandler() { }
virtual void vmobject_deleted(VMObject&) = 0;
};
class VMObject : public RefCounted<VMObject>
, public Weakable<VMObject>
, public InlineLinkedListNode<VMObject> {
@ -71,6 +78,15 @@ public:
ALWAYS_INLINE void unref_region() { m_regions_count--; }
ALWAYS_INLINE bool is_shared_by_multiple_regions() const { return m_regions_count > 1; }
void register_on_deleted_handler(VMObjectDeletedHandler& handler)
{
m_on_deleted.set(&handler);
}
void unregister_on_deleted_handler(VMObjectDeletedHandler& handler)
{
m_on_deleted.remove(&handler);
}
protected:
explicit VMObject(size_t);
explicit VMObject(const VMObject&);
@ -89,6 +105,8 @@ private:
VMObject(VMObject&&) = delete;
Atomic<u32, AK::MemoryOrder::memory_order_relaxed> m_regions_count { 0 };
HashTable<VMObjectDeletedHandler*> m_on_deleted;
SpinLock<u8> m_on_deleted_lock;
};
}