Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: third_party/WebKit/Source/wtf/SpinLock.h

Issue 1502023002: Revert of Switch wtf/SpinLock to std::atomic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/Partitions.cpp ('k') | third_party/WebKit/Source/wtf/SpinLock.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/SpinLock.h
diff --git a/third_party/WebKit/Source/wtf/SpinLock.h b/third_party/WebKit/Source/wtf/SpinLock.h
index b8d6b9c65ed1188e8abae37f2fed0e69d833bf8f..08724a370abb4bb6e4d861dfa267c3ea7ab89f91 100644
--- a/third_party/WebKit/Source/wtf/SpinLock.h
+++ b/third_party/WebKit/Source/wtf/SpinLock.h
@@ -31,48 +31,36 @@
#ifndef WTF_SpinLock_h
#define WTF_SpinLock_h
-#include "wtf/Compiler.h"
-#include "wtf/WTFExport.h"
-#include <atomic>
-#include <memory>
-#include <mutex>
+// DESCRIPTION
+// spinLockLock() and spinLockUnlock() are simple spinlock primitives based on
+// the standard CPU primitive of atomic increment and decrement of an int at
+// a given memory address. These are intended only for very short duration locks
+// and assume a system with multiple cores. For any potentially longer wait you
+// should be using a real lock.
-// DESCRIPTION
-// Spinlock is a simple spinlock class based on the standard CPU primitive of
-// atomic increment and decrement of an int at a given memory address. These are
-// intended only for very short duration locks and assume a system with multiple
-// cores. For any potentially longer wait you should be using a real lock.
+#include "wtf/Atomics.h"
namespace WTF {
-class SpinLock {
-public:
- using Guard = std::lock_guard<SpinLock>;
+// This is called if the initial attempt to acquire the lock fails. It's a bit
+// slower, but has a much better scheduling and power consumption behavior.
+WTF_EXPORT void slowSpinLockLock(int volatile* lock);
- ALWAYS_INLINE void lock()
- {
- static_assert(sizeof(m_lock) == sizeof(int), "int and m_lock are different sizes");
- if (LIKELY(!m_lock.exchange(true, std::memory_order_acq_rel)))
- return;
- lockSlow();
- }
+ALWAYS_INLINE void spinLockLock(int volatile* lock)
+{
+ if (LIKELY(!atomicTestAndSetToOne(lock)))
+ return;
+ slowSpinLockLock(lock);
+}
- ALWAYS_INLINE void unlock()
- {
- m_lock.store(false, std::memory_order_release);
- }
-
-private:
- // This is called if the initial attempt to acquire the lock fails. It's
- // slower, but has a much better scheduling and power consumption behavior.
- WTF_EXPORT void lockSlow();
-
- std::atomic<int> m_lock;
-};
-
+ALWAYS_INLINE void spinLockUnlock(int volatile* lock)
+{
+ atomicSetOneToZero(lock);
+}
} // namespace WTF
-using WTF::SpinLock;
+using WTF::spinLockLock;
+using WTF::spinLockUnlock;
#endif // WTF_SpinLock_h
« no previous file with comments | « third_party/WebKit/Source/wtf/Partitions.cpp ('k') | third_party/WebKit/Source/wtf/SpinLock.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698