Rename SpinLock to Lock. It hasn't been a SpinLock for some time.

I'm pretty happy with the mechanism of AK::Lock for now.
This commit is contained in:
Andreas Kling 2019-01-17 16:25:02 +01:00
parent 133f9aa352
commit e9e57c5f65
Notes: sideshowbarker 2024-07-19 16:00:49 +09:00
9 changed files with 18 additions and 27 deletions

View file

@ -12,12 +12,6 @@ extern Process* current;
#error This thing is kernel-only right now. #error This thing is kernel-only right now.
#endif #endif
//#define DEBUG_LOCKS
void log_try_lock(const char*);
void log_locked(const char*);
void log_unlocked(const char*);
namespace AK { namespace AK {
static inline dword CAS(volatile dword* mem, dword newval, dword oldval) static inline dword CAS(volatile dword* mem, dword newval, dword oldval)
@ -31,17 +25,14 @@ static inline dword CAS(volatile dword* mem, dword newval, dword oldval)
return ret; return ret;
} }
// FIXME: Rename to YieldingLock? RecursiveLock? Maybe just Lock? class Lock {
class SpinLock {
public: public:
SpinLock() { } Lock() { }
~SpinLock() { } ~Lock() { }
void lock(); void lock();
void unlock(); void unlock();
const Process* holder() const { return m_holder; }
private: private:
volatile dword m_lock { 0 }; volatile dword m_lock { 0 };
dword m_level { 0 }; dword m_level { 0 };
@ -50,16 +41,16 @@ private:
class Locker { class Locker {
public: public:
ALWAYS_INLINE explicit Locker(SpinLock& l) : m_lock(l) { lock(); } ALWAYS_INLINE explicit Locker(Lock& l) : m_lock(l) { lock(); }
ALWAYS_INLINE ~Locker() { unlock(); } ALWAYS_INLINE ~Locker() { unlock(); }
ALWAYS_INLINE void unlock() { m_lock.unlock(); } ALWAYS_INLINE void unlock() { m_lock.unlock(); }
ALWAYS_INLINE void lock() { m_lock.lock(); } ALWAYS_INLINE void lock() { m_lock.lock(); }
private: private:
SpinLock& m_lock; Lock& m_lock;
}; };
inline void SpinLock::lock() inline void Lock::lock()
{ {
for (;;) { for (;;) {
if (CAS(&m_lock, 1, 0) == 0) { if (CAS(&m_lock, 1, 0) == 0) {
@ -76,7 +67,7 @@ inline void SpinLock::lock()
} }
} }
inline void SpinLock::unlock() inline void Lock::unlock()
{ {
for (;;) { for (;;) {
if (CAS(&m_lock, 1, 0) == 0) { if (CAS(&m_lock, 1, 0) == 0) {
@ -101,5 +92,5 @@ inline void SpinLock::unlock()
} }
using AK::SpinLock; using AK::Lock;
using AK::Locker; using AK::Locker;

View file

@ -23,7 +23,7 @@ int main(int c, char** v)
StringImpl::initialize_globals(); StringImpl::initialize_globals();
{ {
SpinLock lock; Lock lock;
Locker locker(lock); Locker locker(lock);
} }

View file

@ -30,5 +30,5 @@ private:
Vector<byte> m_buffer2; Vector<byte> m_buffer2;
size_t m_read_buffer_index { 0 }; size_t m_read_buffer_index { 0 };
bool m_empty { true }; bool m_empty { true };
SpinLock m_lock; Lock m_lock;
}; };

View file

@ -37,7 +37,7 @@ private:
bool read_sectors(dword start_sector, word count, byte* buffer); bool read_sectors(dword start_sector, word count, byte* buffer);
bool write_sectors(dword start_sector, word count, const byte* data); bool write_sectors(dword start_sector, word count, const byte* data);
SpinLock m_lock; Lock m_lock;
word m_cylinders { 0 }; word m_cylinders { 0 };
word m_heads { 0 }; word m_heads { 0 };
word m_sectors_per_track { 0 }; word m_sectors_per_track { 0 };

View file

@ -19,6 +19,6 @@ public:
virtual bool can_write(Process&) const override { return true; } virtual bool can_write(Process&) const override { return true; }
private: private:
SpinLock m_lock; Lock m_lock;
Vector<RetainPtr<MasterPTY>> m_freelist; Vector<RetainPtr<MasterPTY>> m_freelist;
}; };

View file

@ -254,7 +254,7 @@ public:
bool is_root() const { return m_euid == 0; } bool is_root() const { return m_euid == 0; }
Vector<GUI_Event>& gui_events() { return m_gui_events; } Vector<GUI_Event>& gui_events() { return m_gui_events; }
SpinLock& gui_events_lock() { return m_gui_events_lock; } Lock& gui_events_lock() { return m_gui_events_lock; }
bool wakeup_requested() { return m_wakeup_requested; } bool wakeup_requested() { return m_wakeup_requested; }
void request_wakeup() { m_wakeup_requested = true; } void request_wakeup() { m_wakeup_requested = true; }
@ -358,7 +358,7 @@ private:
HashMap<int, OwnPtr<WSWindow>> m_windows; HashMap<int, OwnPtr<WSWindow>> m_windows;
Vector<GUI_Event> m_gui_events; Vector<GUI_Event> m_gui_events;
SpinLock m_gui_events_lock; Lock m_gui_events_lock;
int m_next_window_id { 1 }; int m_next_window_id { 1 };
dword m_wakeup_requested { false }; dword m_wakeup_requested { false };

View file

@ -47,7 +47,7 @@ private:
const Ext2FS& fs() const; const Ext2FS& fs() const;
Ext2FSInode(Ext2FS&, unsigned index, const ext2_inode&); Ext2FSInode(Ext2FS&, unsigned index, const ext2_inode&);
SpinLock m_lock; Lock m_lock;
Vector<unsigned> m_block_list; Vector<unsigned> m_block_list;
HashMap<String, unsigned> m_lookup_cache; HashMap<String, unsigned> m_lookup_cache;
ext2_inode m_raw_inode; ext2_inode m_raw_inode;
@ -110,7 +110,7 @@ private:
mutable ByteBuffer m_cached_super_block; mutable ByteBuffer m_cached_super_block;
mutable ByteBuffer m_cached_group_descriptor_table; mutable ByteBuffer m_cached_group_descriptor_table;
mutable SpinLock m_inode_cache_lock; mutable Lock m_inode_cache_lock;
mutable HashMap<BlockIndex, RetainPtr<Ext2FSInode>> m_inode_cache; mutable HashMap<BlockIndex, RetainPtr<Ext2FSInode>> m_inode_cache;
}; };

View file

@ -29,7 +29,7 @@ private:
void drain_mouse(); void drain_mouse();
void drain_keyboard(); void drain_keyboard();
SpinLock m_lock; Lock m_lock;
struct QueuedEvent { struct QueuedEvent {
WSEventReceiver* receiver { nullptr }; WSEventReceiver* receiver { nullptr };

View file

@ -92,5 +92,5 @@ private:
OwnPtr<Painter> m_back_painter; OwnPtr<Painter> m_back_painter;
OwnPtr<Painter> m_front_painter; OwnPtr<Painter> m_front_painter;
mutable SpinLock m_lock; mutable Lock m_lock;
}; };