Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 525d3a21c902651fe39f6b2df739635b07633e8c 1 parent 442465b
@mrobinson mrobinson authored
Showing with 29 additions and 2 deletions.
  1. +29 −2 Source/WTF/wtf/TCSpinLock.h
View
31 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);
Please sign in to comment.
Something went wrong with that request. Please try again.