diff options
-rw-r--r-- | dm/DM.cpp | 10 | ||||
-rw-r--r-- | include/private/SkOnce.h | 2 | ||||
-rw-r--r-- | include/private/SkSpinlock.h | 24 | ||||
-rw-r--r-- | src/core/SkSpinlock.cpp | 8 | ||||
-rw-r--r-- | src/gpu/GrProcessor.cpp | 2 | ||||
-rw-r--r-- | src/gpu/batches/GrBatch.cpp | 2 |
6 files changed, 20 insertions, 28 deletions
@@ -84,7 +84,7 @@ static void fail(const SkString& err) { // We use a spinlock to make locking this in a signal handler _somewhat_ safe. -SK_DECLARE_STATIC_SPINLOCK(gMutex); +static SkSpinlock gMutex; static int32_t gPending; static SkTArray<SkString> gRunning; @@ -92,7 +92,7 @@ static void done(const char* config, const char* src, const char* srcOptions, co SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); int pending; { - SkAutoTAcquire<SkPODSpinlock> lock(gMutex); + SkAutoTAcquire<SkSpinlock> lock(gMutex); for (int i = 0; i < gRunning.count(); i++) { if (gRunning[i] == id) { gRunning.removeShuffle(i); @@ -110,7 +110,7 @@ static void done(const char* config, const char* src, const char* srcOptions, co static void start(const char* config, const char* src, const char* srcOptions, const char* name) { SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); - SkAutoTAcquire<SkPODSpinlock> lock(gMutex); + SkAutoTAcquire<SkSpinlock> lock(gMutex); gRunning.push_back(id); } @@ -121,7 +121,7 @@ static void print_status() { peak = sk_tools::getMaxResidentSetSizeMB(); SkString elapsed = HumanizeMs(SkTime::GetMSecs() - start_ms); - SkAutoTAcquire<SkPODSpinlock> lock(gMutex); + SkAutoTAcquire<SkSpinlock> lock(gMutex); SkDebugf("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n", elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, peak); for (auto& task : gRunning) { @@ -1242,7 +1242,7 @@ int dm_main() { if (src->veto(sink->flags()) || is_blacklisted(sink.tag.c_str(), src.tag.c_str(), src.options.c_str(), src->name().c_str())) { - SkAutoTAcquire<SkPODSpinlock> lock(gMutex); + SkAutoTAcquire<SkSpinlock> lock(gMutex); gPending--; continue; } diff --git a/include/private/SkOnce.h b/include/private/SkOnce.h index a3ef4d6713..5434d9d7d9 100644 --- a/include/private/SkOnce.h +++ b/include/private/SkOnce.h @@ -59,7 +59,7 @@ public: private: bool fDone; - SkPODSpinlock fSpinlock; + SkSpinlock fSpinlock; }; // We've pulled a pretty standard double-checked locking implementation apart diff --git a/include/private/SkSpinlock.h b/include/private/SkSpinlock.h index ef52ab013a..a049f1f726 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 diff --git a/src/core/SkSpinlock.cpp b/src/core/SkSpinlock.cpp index 0f764278df..eb9d6330aa 100644 --- a/src/core/SkSpinlock.cpp +++ b/src/core/SkSpinlock.cpp @@ -7,7 +7,9 @@ #include "SkSpinlock.h" -void SkPODSpinlock::contendedAcquire() { - // To act as a mutex, we need an acquire barrier when we take the lock. - while(sk_atomic_exchange(&fLocked, true, sk_memory_order_acquire)) { /*spin*/ } +void SkSpinlock::contendedAcquire() { + // To act as a mutex, we need an acquire barrier when we acquire the lock. + while (fLocked.exchange(true, std::memory_order_acquire)) { + /*spin*/ + } } diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp index 15206c2c85..aef51908da 100644 --- a/src/gpu/GrProcessor.cpp +++ b/src/gpu/GrProcessor.cpp @@ -81,7 +81,7 @@ void GrProcessorTestFactory<GrXPFactory>::VerifyFactoryCount() { // memory barrier between accesses of a context on different threads. Also, there may be multiple // GrContexts and those contexts may be in use concurrently on different threads. namespace { -SK_DECLARE_STATIC_SPINLOCK(gProcessorSpinlock); +static SkSpinlock gProcessorSpinlock; class MemoryPoolAccessor { public: MemoryPoolAccessor() { gProcessorSpinlock.acquire(); } diff --git a/src/gpu/batches/GrBatch.cpp b/src/gpu/batches/GrBatch.cpp index 19c19ffcf1..8af1c1e088 100644 --- a/src/gpu/batches/GrBatch.cpp +++ b/src/gpu/batches/GrBatch.cpp @@ -20,7 +20,7 @@ // memory barrier between accesses of a context on different threads. Also, there may be multiple // GrContexts and those contexts may be in use concurrently on different threads. namespace { -SK_DECLARE_STATIC_SPINLOCK(gBatchSpinlock); +static SkSpinlock gBatchSpinlock; class MemoryPoolAccessor { public: MemoryPoolAccessor() { gBatchSpinlock.acquire(); } |