⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181461 in webkit


Ignore:
Timestamp:
Mar 12, 2015, 5:20:18 PM (11 years ago)
Author:
mark.lam@apple.com
Message:

Change WTF::ByteSpinLock to use std::atomic.
<https://webkit.org/b/142644>

Reviewed by Filip Pizlo.

  • wtf/ByteSpinLock.h:

(WTF::ByteSpinLock::ByteSpinLock):
(WTF::ByteSpinLock::lock):
(WTF::ByteSpinLock::unlock):
(WTF::ByteSpinLock::isHeld):

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r181436 r181461  
     12015-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
    1142015-03-12  Csaba Osztrogonác  <ossy@webkit.org>
    215
  • trunk/Source/WTF/wtf/ByteSpinLock.h

    r161164 r181461  
    2727#define ByteSpinLock_h
    2828
     29#include <atomic>
    2930#include <thread>
    3031#include <wtf/Assertions.h>
    31 #include <wtf/Atomics.h>
    3232#include <wtf/Locker.h>
    3333#include <wtf/Noncopyable.h>
     
    3939public:
    4040    ByteSpinLock()
    41         : m_lock(0)
     41        : m_lock(false)
    4242    {
    4343    }
     
    4545    void lock()
    4646    {
    47         while (!weakCompareAndSwap(&m_lock, 0, 1))
     47        bool expected = false;
     48        while (!m_lock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
    4849            std::this_thread::yield();
    49         memoryBarrierAfterLock();
     50            expected = false;
     51        }
    5052    }
    5153   
    5254    void unlock()
    5355    {
    54         memoryBarrierBeforeUnlock();
    55         m_lock = 0;
     56        m_lock.store(false, std::memory_order_release);
    5657    }
    5758   
    58     bool isHeld() const { return !!m_lock; }
     59    bool isHeld() const { return m_lock.load(std::memory_order_acquire); }
    5960   
    6061private:
    61     uint8_t m_lock;
     62    std::atomic<bool> m_lock;
    6263};
    6364
Note: See TracChangeset for help on using the changeset viewer.