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

Unified Diff: include/private/SkSpinlock.h

Issue 1734383002: Modernize SkSpinlock. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: std::atomic<bool> Created 4 years, 10 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 | « include/private/SkOnce.h ('k') | src/core/SkSpinlock.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/SkSpinlock.h
diff --git a/include/private/SkSpinlock.h b/include/private/SkSpinlock.h
index ef52ab013a0d08c6ea5f3f7d7d2d57f20c8483a7..a049f1f726a8db827e6610c026ce18aa43c15922 100644
--- a/include/private/SkSpinlock.h
+++ b/include/private/SkSpinlock.h
@@ -5,40 +5,30 @@
* found in the LICENSE file.
*/
-// This file is not part of the public Skia API.
-
#ifndef SkSpinlock_DEFINED
#define SkSpinlock_DEFINED
-#include "../private/SkAtomics.h"
-
-#define SK_DECLARE_STATIC_SPINLOCK(name) namespace {} static SkPODSpinlock name
+#include <atomic>
-// This class has no constructor and must be zero-initialized (the macro above does this).
-class SK_API SkPODSpinlock {
+class SkSpinlock {
public:
void acquire() {
- // 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)) {
+ // To act as a mutex, we need an acquire barrier when we acquire the lock.
+ if (fLocked.exchange(true, std::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);
+ // To act as a mutex, we need a release barrier when we release the lock.
+ fLocked.store(false, std::memory_order_release);
}
private:
void contendedAcquire();
- bool fLocked;
-};
-// For non-global-static use cases, this is normally what you want.
-class SkSpinlock : public SkPODSpinlock {
-public:
- SkSpinlock() { this->release(); }
+ std::atomic<bool> fLocked{false};
};
#endif//SkSpinlock_DEFINED
« no previous file with comments | « include/private/SkOnce.h ('k') | src/core/SkSpinlock.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698