Skip to content

Commit

Permalink
Merge r181461 - Change WTF::ByteSpinLock to use std::atomic.
Browse files Browse the repository at this point in the history
<https://webkit.org/b/142644>

Reviewed by Filip Pizlo.

* wtf/ByteSpinLock.h:
(WTF::ByteSpinLock::ByteSpinLock):
(WTF::ByteSpinLock::lock):
(WTF::ByteSpinLock::unlock):
(WTF::ByteSpinLock::isHeld):
  • Loading branch information
Mark Lam authored and carlosgcampos committed Mar 16, 2015
1 parent 30f7ca1 commit 669f200
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
13 changes: 13 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,16 @@
2015-03-12 Mark Lam <mark.lam@apple.com>

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):

2015-03-12 Csaba Osztrogonác <ossy@webkit.org>

[ARM][Linux] GC sometimes stuck in an infinite loop if parallel GC is enabled
Expand Down
17 changes: 9 additions & 8 deletions Source/WTF/wtf/ByteSpinLock.h
Expand Up @@ -26,9 +26,9 @@
#ifndef ByteSpinLock_h
#define ByteSpinLock_h

#include <atomic>
#include <thread>
#include <wtf/Assertions.h>
#include <wtf/Atomics.h>
#include <wtf/Locker.h>
#include <wtf/Noncopyable.h>

Expand All @@ -38,27 +38,28 @@ class ByteSpinLock {
WTF_MAKE_NONCOPYABLE(ByteSpinLock);
public:
ByteSpinLock()
: m_lock(0)
: m_lock(false)
{
}

void lock()
{
while (!weakCompareAndSwap(&m_lock, 0, 1))
bool expected = false;
while (!m_lock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
std::this_thread::yield();
memoryBarrierAfterLock();
expected = false;
}
}

void unlock()
{
memoryBarrierBeforeUnlock();
m_lock = 0;
m_lock.store(false, std::memory_order_release);
}

bool isHeld() const { return !!m_lock; }
bool isHeld() const { return m_lock.load(std::memory_order_acquire); }

private:
uint8_t m_lock;
std::atomic<bool> m_lock;
};

typedef Locker<ByteSpinLock> ByteSpinLocker;
Expand Down

0 comments on commit 669f200

Please sign in to comment.