Skip to content

Commit

Permalink
Kernel+Userland: Remove global futexes
Browse files Browse the repository at this point in the history
We only ever use private futexes, so it doesn't make sense to carry
around all the complexity required for global (cross-process) futexes.
  • Loading branch information
awesomekling committed Aug 16, 2021
1 parent 7979b5a commit 4226b66
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 188 deletions.
3 changes: 1 addition & 2 deletions Kernel/API/POSIX/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ extern "C" {
#define FUTEX_WAIT_BITSET 9
#define FUTEX_WAKE_BITSET 10

#define FUTEX_PRIVATE_FLAG (1 << 7)
#define FUTEX_CLOCK_REALTIME (1 << 8)
#define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
#define FUTEX_CMD_MASK ~(FUTEX_CLOCK_REALTIME)

#define FUTEX_BITSET_MATCH_ANY 0xffffffff

Expand Down
8 changes: 8 additions & 0 deletions Kernel/FutexQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

namespace Kernel {

FutexQueue::FutexQueue()
{
}

FutexQueue::~FutexQueue()
{
}

bool FutexQueue::should_add_blocker(Thread::Blocker& b, void* data)
{
VERIFY(data != nullptr); // Thread that is requesting to be blocked
Expand Down
15 changes: 4 additions & 11 deletions Kernel/FutexQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

namespace Kernel {

class FutexQueue : public Thread::BlockCondition
, public RefCounted<FutexQueue>
, public Memory::VMObjectDeletedHandler {
class FutexQueue
: public RefCounted<FutexQueue>
, public Thread::BlockCondition {
public:
FutexQueue(FlatPtr user_address_or_offset, Memory::VMObject* vmobject = nullptr);
FutexQueue();
virtual ~FutexQueue();

u32 wake_n_requeue(u32, const Function<FutexQueue*()>&, u32, bool&, bool&);
Expand All @@ -31,8 +31,6 @@ class FutexQueue : public Thread::BlockCondition
return Thread::current()->block<Thread::FutexBlocker>(timeout, *this, forward<Args>(args)...);
}

virtual void vmobject_deleted(Memory::VMObject&) override;

bool queue_imminent_wait();
void did_remove();
bool try_remove();
Expand All @@ -48,11 +46,6 @@ class FutexQueue : public Thread::BlockCondition
virtual bool should_add_blocker(Thread::Blocker& b, void* data) override;

private:
// For private futexes we just use the user space address.
// But for global futexes we use the offset into the VMObject
const FlatPtr m_user_address_or_offset;
WeakPtr<Memory::VMObject> m_vmobject;
const bool m_is_global;
size_t m_imminent_waits { 1 }; // We only create this object if we're going to be waiting, so start out with 1
bool m_was_removed { false };
};
Expand Down
7 changes: 0 additions & 7 deletions Kernel/Memory/VMObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ VMObject::VMObject(size_t size)

VMObject::~VMObject()
{
{
ScopedSpinLock lock(m_on_deleted_lock);
for (auto& it : m_on_deleted)
it->vmobject_deleted(*this);
m_on_deleted.clear();
}

VERIFY(m_regions.is_empty());
}

Expand Down
23 changes: 0 additions & 23 deletions Kernel/Memory/VMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
#pragma once

#include <AK/FixedArray.h>
#include <AK/HashTable.h>
#include <AK/IntrusiveList.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/Vector.h>
#include <AK/Weakable.h>
#include <Kernel/Forward.h>
#include <Kernel/Library/ListedRefCounted.h>
Expand All @@ -20,12 +17,6 @@

namespace Kernel::Memory {

class VMObjectDeletedHandler {
public:
virtual ~VMObjectDeletedHandler() = default;
virtual void vmobject_deleted(VMObject&) = 0;
};

class VMObject
: public ListedRefCounted<VMObject>
, public Weakable<VMObject> {
Expand Down Expand Up @@ -63,17 +54,6 @@ class VMObject
m_regions.remove(region);
}

void register_on_deleted_handler(VMObjectDeletedHandler& handler)
{
ScopedSpinLock locker(m_on_deleted_lock);
m_on_deleted.set(&handler);
}
void unregister_on_deleted_handler(VMObjectDeletedHandler& handler)
{
ScopedSpinLock locker(m_on_deleted_lock);
m_on_deleted.remove(&handler);
}

protected:
explicit VMObject(size_t);
explicit VMObject(VMObject const&);
Expand All @@ -91,9 +71,6 @@ class VMObject
VMObject& operator=(VMObject&&) = delete;
VMObject(VMObject&&) = delete;

HashTable<VMObjectDeletedHandler*> m_on_deleted;
SpinLock<u8> m_on_deleted_lock;

Region::ListInVMObject m_regions;

public:
Expand Down
Loading

0 comments on commit 4226b66

Please sign in to comment.