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

Unified Diff: include/core/SkOnce.h

Issue 1039323002: Extract the spinlock from SkOnce as SkSpinlock. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: quotes Created 5 years, 9 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
Index: include/core/SkOnce.h
diff --git a/include/core/SkOnce.h b/include/core/SkOnce.h
index c26c49fca57f79465ad76869f6851d3b084c3c2e..a4188d08f061827395d4cb282a29a414bb361509 100644
--- a/include/core/SkOnce.h
+++ b/include/core/SkOnce.h
@@ -28,6 +28,7 @@
// OnceTest.cpp also should serve as a few other simple examples.
#include "SkAtomics.h"
+#include "SkSpinlock.h"
// This must be used in a global scope, not in fuction scope or as a class member.
#define SK_DECLARE_STATIC_ONCE(name) namespace {} static SkOnceFlag name
@@ -53,24 +54,12 @@ class SkOnceFlag {
public:
bool* mutableDone() { return &fDone; }
- void acquire() {
- // To act as a mutex, this needs an acquire barrier on success.
- // sk_atomic_cas doesn't guarantee this ...
- while (!sk_atomic_cas(&fSpinlock, 0, 1)) {
- // spin
- }
- // ... so make sure to issue one of our own.
- SkAssertResult(sk_acquire_load(&fSpinlock));
- }
-
- void release() {
- // To act as a mutex, this needs a release barrier. sk_atomic_cas guarantees this.
- SkAssertResult(sk_atomic_cas(&fSpinlock, 1, 0));
- }
+ void acquire() { fSpinlock.acquire(); }
+ void release() { fSpinlock.release(); }
private:
bool fDone;
- int32_t fSpinlock;
+ SkPODSpinlock fSpinlock;
};
// We've pulled a pretty standard double-checked locking implementation apart

Powered by Google App Engine
This is Rietveld 408576698