Permalink
Browse files

Rewrite TCMalloc_SpinLock against C++ atomics

Memory fences seem to have issues on Windows ARM, so this commit
replaces the platform-specific implementation with one that works
on all C++11 platforms.
  • Loading branch information...
1 parent 442465b commit 525d3a21c902651fe39f6b2df739635b07633e8c @mrobinson mrobinson committed Oct 21, 2013
Showing with 29 additions and 2 deletions.
  1. +29 −2 Source/WTF/wtf/TCSpinLock.h
@@ -40,10 +40,37 @@
#endif
#if OS(WINDOWS_PHONE)
-#include <thread>
+#include <atomic>
#endif
-#if ENABLE(COMPARE_AND_SWAP)
+#if USE(STDTHREAD)
+
+struct TCMalloc_SpinLock {
+ void Lock() {
+ while (m_lock.exchange(true)) { }
+ }
+
+ void Unlock() {
+ m_lock = false;
+ }
+
+ // Report if we think the lock can be held by this thread.
+ // When the lock is truly held by the invoking thread
+ // we will always return true.
+ // Indended to be used as CHECK(lock.IsHeld());
+ bool IsHeld() const {
+ return m_lock;
+ }
+
+ void Init() { m_lock = false; }
+ void Finalize() { }
+
+ std::atomic<bool> m_lock;
+};
+
+#define SPINLOCK_INITIALIZER { 0 }
+
+#elif ENABLE(COMPARE_AND_SWAP)
static void TCMalloc_SlowLock(unsigned* lockword);

0 comments on commit 525d3a2

Please sign in to comment.