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

Unified Diff: include/core/SkSpinlock.h

Issue 1212253013: Outline SkSpinlock::acquire(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: doc Created 5 years, 5 months 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 | « gyp/core.gypi ('k') | src/core/SkSpinlock.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkSpinlock.h
diff --git a/include/core/SkSpinlock.h b/include/core/SkSpinlock.h
index 68a6ff7b1246bcd216327a683a36d75148f2845b..6edfdf0367296cd114c93c5edc02d95736320285 100644
--- a/include/core/SkSpinlock.h
+++ b/include/core/SkSpinlock.h
@@ -15,16 +15,23 @@
#define SK_DECLARE_STATIC_SPINLOCK(name) namespace {} static SkPODSpinlock name
// This class has no constructor and must be zero-initialized (the macro above does this).
-struct SkPODSpinlock {
+class SkPODSpinlock {
+public:
void acquire() {
- // To act as a mutex, we need an acquire barrier.
- while(sk_atomic_exchange(&fLocked, true, sk_memory_order_acquire)) { /*spin*/ }
+ // To act as a mutex, we need an acquire barrier if we take the lock.
+ if (sk_atomic_exchange(&fLocked, true, sk_memory_order_acquire)) {
+ // Lock was contended. Fall back to an out-of-line spin loop.
+ this->contendedAcquire();
+ }
}
+
void release() {
// To act as a mutex, we need a release barrier.
sk_atomic_store(&fLocked, false, sk_memory_order_release);
}
+private:
+ void contendedAcquire();
bool fLocked;
};
« no previous file with comments | « gyp/core.gypi ('k') | src/core/SkSpinlock.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698