Przeglądaj źródła

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.
Andreas Kling 6 lat temu
rodzic
commit
e9e57c5f65

+ 8 - 17
AK/Lock.h

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

+ 1 - 1
AK/test.cpp

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

+ 1 - 1
Kernel/DoubleBuffer.h

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

+ 1 - 1
Kernel/IDEDiskDevice.h

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

+ 1 - 1
Kernel/PTYMultiplexer.h

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

+ 2 - 2
Kernel/Process.h

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

+ 2 - 2
VirtualFileSystem/Ext2FileSystem.h

@@ -47,7 +47,7 @@ private:
     const Ext2FS& fs() const;
     Ext2FSInode(Ext2FS&, unsigned index, const ext2_inode&);
 
-    SpinLock m_lock;
+    Lock m_lock;
     Vector<unsigned> m_block_list;
     HashMap<String, unsigned> m_lookup_cache;
     ext2_inode m_raw_inode;
@@ -110,7 +110,7 @@ private:
     mutable ByteBuffer m_cached_super_block;
     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;
 };
 

+ 1 - 1
WindowServer/WSEventLoop.h

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

+ 1 - 1
WindowServer/WSWindowManager.h

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