Changeset 181461 in webkit
- Timestamp:
- Mar 12, 2015, 5:20:18 PM (11 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
wtf/ByteSpinLock.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r181436 r181461 1 2015-03-12 Mark Lam <mark.lam@apple.com> 2 3 Change WTF::ByteSpinLock to use std::atomic. 4 <https://webkit.org/b/142644> 5 6 Reviewed by Filip Pizlo. 7 8 * wtf/ByteSpinLock.h: 9 (WTF::ByteSpinLock::ByteSpinLock): 10 (WTF::ByteSpinLock::lock): 11 (WTF::ByteSpinLock::unlock): 12 (WTF::ByteSpinLock::isHeld): 13 1 14 2015-03-12 Csaba Osztrogonác <ossy@webkit.org> 2 15 -
trunk/Source/WTF/wtf/ByteSpinLock.h
r161164 r181461 27 27 #define ByteSpinLock_h 28 28 29 #include <atomic> 29 30 #include <thread> 30 31 #include <wtf/Assertions.h> 31 #include <wtf/Atomics.h>32 32 #include <wtf/Locker.h> 33 33 #include <wtf/Noncopyable.h> … … 39 39 public: 40 40 ByteSpinLock() 41 : m_lock( 0)41 : m_lock(false) 42 42 { 43 43 } … … 45 45 void lock() 46 46 { 47 while (!weakCompareAndSwap(&m_lock, 0, 1)) 47 bool expected = false; 48 while (!m_lock.compare_exchange_weak(expected, true, std::memory_order_acquire)) { 48 49 std::this_thread::yield(); 49 memoryBarrierAfterLock(); 50 expected = false; 51 } 50 52 } 51 53 52 54 void unlock() 53 55 { 54 memoryBarrierBeforeUnlock(); 55 m_lock = 0; 56 m_lock.store(false, std::memory_order_release); 56 57 } 57 58 58 bool isHeld() const { return !!m_lock; }59 bool isHeld() const { return m_lock.load(std::memory_order_acquire); } 59 60 60 61 private: 61 uint8_tm_lock;62 std::atomic<bool> m_lock; 62 63 }; 63 64
Note:
See TracChangeset
for help on using the changeset viewer.