remove sk_atomic_inc
Change-Id: I4960b1cd055daf44637e95825f82cb7fe2ce134a
Reviewed-on: https://skia-review.googlesource.com/c/174285
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/bench/RefCntBench.cpp b/bench/RefCntBench.cpp
index f6aa3de..39b3a73 100644
--- a/bench/RefCntBench.cpp
+++ b/bench/RefCntBench.cpp
@@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
#include "Benchmark.h"
-#include "SkAtomics.h"
#include "SkRefCnt.h"
#include "SkWeakRefCnt.h"
#include <memory>
@@ -15,30 +14,6 @@
M = 2
};
-class AtomicInc32 : public Benchmark {
-public:
- AtomicInc32() : fX(0) {}
-
- bool isSuitableFor(Backend backend) override {
- return backend == kNonRendering_Backend;
- }
-
-protected:
- const char* onGetName() override {
- return "atomic_inc_32";
- }
-
- void onDraw(int loops, SkCanvas*) override {
- for (int i = 0; i < loops; ++i) {
- sk_atomic_inc(&fX);
- }
- }
-
-private:
- int32_t fX;
- typedef Benchmark INHERITED;
-};
-
class RefCntBench_Stack : public Benchmark {
public:
bool isSuitableFor(Backend backend) override {
@@ -214,8 +189,6 @@
///////////////////////////////////////////////////////////////////////////////
-DEF_BENCH( return new AtomicInc32(); )
-
DEF_BENCH( return new RefCntBench_Stack(); )
DEF_BENCH( return new RefCntBench_Heap(); )
DEF_BENCH( return new RefCntBench_New(); )
diff --git a/gn/core.gni b/gn/core.gni
index e51d9c5..19bf772 100644
--- a/gn/core.gni
+++ b/gn/core.gni
@@ -422,7 +422,6 @@
# private
"$_include/private/SkArenaAlloc.h",
- "$_include/private/SkAtomics.h",
"$_include/private/SkChecksum.h",
"$_include/private/SkDeferredDisplayList.h",
"$_include/private/SkFixed.h",
diff --git a/include/private/SkAtomics.h b/include/private/SkAtomics.h
deleted file mode 100644
index cc85509..0000000
--- a/include/private/SkAtomics.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkAtomics_DEFINED
-#define SkAtomics_DEFINED
-
-#include "SkTypes.h"
-#include <atomic>
-
-// ~~~~~~~~ Very Legacy APIs ~~~~~~~~~
-//
-// Here are shims for our very old atomics API, to be weaned off of. They use
-// sequentially-consistent memory order to match historical behavior, but most
-// of the callers could perform better with explicit, weaker memory ordering.
-
-inline int32_t sk_atomic_inc(int32_t* ptr) {
- return reinterpret_cast<std::atomic<int32_t>*>(ptr)->fetch_add(+1);
-}
-
-#endif//SkAtomics_DEFINED
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 8aba794..5b70168 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -7,7 +7,6 @@
#include "SkBitmap.h"
-#include "SkAtomics.h"
#include "SkColorData.h"
#include "SkConvertPixels.h"
#include "SkData.h"
diff --git a/src/core/SkClipStack.cpp b/src/core/SkClipStack.cpp
index 97c0af2..334ef1f 100644
--- a/src/core/SkClipStack.cpp
+++ b/src/core/SkClipStack.cpp
@@ -5,20 +5,14 @@
* found in the LICENSE file.
*/
-#include "SkAtomics.h"
#include "SkCanvas.h"
#include "SkClipStack.h"
#include "SkPath.h"
#include "SkPathOps.h"
#include "SkClipOpPriv.h"
-
+#include <atomic>
#include <new>
-
-// 0-2 are reserved for invalid, empty & wide-open
-static const int32_t kFirstUnreservedGenID = 3;
-int32_t SkClipStack::gGenID = kFirstUnreservedGenID;
-
SkClipStack::Element::Element(const Element& that) {
switch (that.getDeviceSpaceType()) {
case DeviceSpaceType::kEmpty:
@@ -1004,9 +998,13 @@
}
uint32_t SkClipStack::GetNextGenID() {
+ // 0-2 are reserved for invalid, empty & wide-open
+ static const uint32_t kFirstUnreservedGenID = 3;
+ static std::atomic<uint32_t> nextID{kFirstUnreservedGenID};
+
uint32_t id;
do {
- id = static_cast<uint32_t>(sk_atomic_inc(&gGenID));
+ id = nextID++;
} while (id < kFirstUnreservedGenID);
return id;
}
diff --git a/src/core/SkClipStack.h b/src/core/SkClipStack.h
index 050f30ed..e96a47f 100644
--- a/src/core/SkClipStack.h
+++ b/src/core/SkClipStack.h
@@ -489,10 +489,6 @@
SkDeque fDeque;
int fSaveCount;
- // Generation ID for the clip stack. This is incremented for each
- // clipDevRect and clipDevPath call. 0 is reserved to indicate an
- // invalid ID.
- static int32_t gGenID;
SkRect fClipRestrictionRect = SkRect::MakeEmpty();
bool internalQuickContains(const SkRect& devRect) const;
diff --git a/src/core/SkDrawable.cpp b/src/core/SkDrawable.cpp
index bf6d39c..034bacc 100644
--- a/src/core/SkDrawable.cpp
+++ b/src/core/SkDrawable.cpp
@@ -5,20 +5,18 @@
* found in the LICENSE file.
*/
-#include "SkAtomics.h"
#include "SkCanvas.h"
#include "SkDrawable.h"
+#include <atomic>
static int32_t next_generation_id() {
- static int32_t gCanvasDrawableGenerationID;
+ static std::atomic<int32_t> nextID{1};
- // do a loop in case our global wraps around, as we never want to
- // return a 0
- int32_t genID;
+ int32_t id;
do {
- genID = sk_atomic_inc(&gCanvasDrawableGenerationID) + 1;
- } while (0 == genID);
- return genID;
+ id = nextID++;
+ } while (id == 0);
+ return id;
}
SkDrawable::SkDrawable() : fGenerationID(0) {}
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 01b7683..4de7124 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -7,7 +7,6 @@
#include "SkImageFilter.h"
-#include "SkAtomics.h"
#include "SkCanvas.h"
#include "SkFuzzLogging.h"
#include "SkImageFilterCache.h"
@@ -28,6 +27,7 @@
#include "GrTextureProxy.h"
#include "SkGr.h"
#endif
+#include <atomic>
void SkImageFilter::CropRect::applyTo(const SkIRect& imageBounds,
const SkMatrix& ctm,
@@ -70,13 +70,12 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
static int32_t next_image_filter_unique_id() {
- static int32_t gImageFilterUniqueID;
+ static std::atomic<int32_t> nextID{1};
- // Never return 0.
int32_t id;
do {
- id = sk_atomic_inc(&gImageFilterUniqueID) + 1;
- } while (0 == id);
+ id = nextID++;
+ } while (id == 0);
return id;
}
diff --git a/src/core/SkRWBuffer.cpp b/src/core/SkRWBuffer.cpp
index 69e4a2e..6e180a6 100644
--- a/src/core/SkRWBuffer.cpp
+++ b/src/core/SkRWBuffer.cpp
@@ -7,7 +7,6 @@
#include "SkRWBuffer.h"
-#include "SkAtomics.h"
#include "SkMakeUnique.h"
#include "SkMalloc.h"
#include "SkStream.h"
diff --git a/src/core/SkSharedMutex.cpp b/src/core/SkSharedMutex.cpp
index 74bea77..fa26053 100644
--- a/src/core/SkSharedMutex.cpp
+++ b/src/core/SkSharedMutex.cpp
@@ -7,7 +7,6 @@
#include "SkSharedMutex.h"
-#include "SkAtomics.h"
#include "SkTypes.h"
#include "SkSemaphore.h"
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index 6f7d80d..b6ac84e 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -7,7 +7,6 @@
#include "SkString.h"
-#include "SkAtomics.h"
#include "SkSafeMath.h"
#include "SkTo.h"
#include "SkUtils.h"
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp
index ac972a1..f050838 100644
--- a/src/core/SkTextBlob.cpp
+++ b/src/core/SkTextBlob.cpp
@@ -7,7 +7,6 @@
#include "SkTextBlob.h"
-#include "SkAtomics.h"
#include "SkGlyphRun.h"
#include "SkPaintPriv.h"
#include "SkReadBuffer.h"
@@ -16,6 +15,7 @@
#include "SkTypeface.h"
#include "SkWriteBuffer.h"
+#include <atomic>
#include <limits>
#include <new>
@@ -157,11 +157,11 @@
memmove(posBuffer(), initialPosBuffer, copySize);
}
-static int32_t gNextID = 1;
static int32_t next_id() {
+ static std::atomic<int32_t> nextID{1};
int32_t id;
do {
- id = sk_atomic_inc(&gNextID);
+ id = nextID++;
} while (id == SK_InvalidGenID);
return id;
}
diff --git a/src/core/SkTypefaceCache.cpp b/src/core/SkTypefaceCache.cpp
index 3728b13..0cf0d84 100644
--- a/src/core/SkTypefaceCache.cpp
+++ b/src/core/SkTypefaceCache.cpp
@@ -5,11 +5,9 @@
* found in the LICENSE file.
*/
-
-
#include "SkTypefaceCache.h"
-#include "SkAtomics.h"
#include "SkMutex.h"
+#include <atomic>
#define TYPEFACE_CACHE_LIMIT 1024
@@ -60,8 +58,8 @@
}
SkFontID SkTypefaceCache::NewFontID() {
- static int32_t gFontID;
- return sk_atomic_inc(&gFontID) + 1;
+ static std::atomic<int32_t> nextID{1};
+ return nextID++;
}
SK_DECLARE_STATIC_MUTEX(gMutex);
diff --git a/src/core/SkVertices.cpp b/src/core/SkVertices.cpp
index a3a3989..ac7efef 100644
--- a/src/core/SkVertices.cpp
+++ b/src/core/SkVertices.cpp
@@ -7,20 +7,21 @@
#include "SkVertices.h"
-#include "SkAtomics.h"
#include "SkData.h"
#include "SkReader32.h"
#include "SkSafeMath.h"
#include "SkSafeRange.h"
#include "SkTo.h"
#include "SkWriter32.h"
+#include <atomic>
#include <new>
-static int32_t gNextID = 1;
static int32_t next_id() {
+ static std::atomic<int32_t> nextID{1};
+
int32_t id;
do {
- id = sk_atomic_inc(&gNextID);
+ id = nextID++;
} while (id == SK_InvalidGenID);
return id;
}
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index d962bbd..06eb6c4 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -6,7 +6,6 @@
*/
#include "GrContext.h"
-#include <unordered_map>
#include "GrBackendSemaphore.h"
#include "GrClip.h"
#include "GrContextOptions.h"
@@ -39,6 +38,8 @@
#include "effects/GrSkSLFP.h"
#include "ccpr/GrCoverageCountingPathRenderer.h"
#include "text/GrTextBlobCache.h"
+#include <atomic>
+#include <unordered_map>
#define ASSERT_OWNED_PROXY(P) \
SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == this)
@@ -58,11 +59,11 @@
////////////////////////////////////////////////////////////////////////////////
-static int32_t gNextID = 1;
static int32_t next_id() {
+ static std::atomic<int32_t> nextID{1};
int32_t id;
do {
- id = sk_atomic_inc(&gNextID);
+ id = nextID++;
} while (id == SK_InvalidGenID);
return id;
}
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index 0ff6076..a4e0f54 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -12,6 +12,7 @@
#include "GrGpu.h"
#include "GrGpuResourcePriv.h"
#include "SkTraceMemoryDump.h"
+#include <atomic>
static inline GrResourceCache* get_resource_cache(GrGpu* gpu) {
SkASSERT(gpu);
@@ -206,10 +207,10 @@
}
uint32_t GrGpuResource::CreateUniqueID() {
- static int32_t gUniqueID = SK_InvalidUniqueID;
+ static std::atomic<uint32_t> nextID{1};
uint32_t id;
do {
- id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
+ id = nextID++;
} while (id == SK_InvalidUniqueID);
return id;
}
diff --git a/src/gpu/GrMemoryPool.cpp b/src/gpu/GrMemoryPool.cpp
index 89e8f01..1366c4c 100644
--- a/src/gpu/GrMemoryPool.cpp
+++ b/src/gpu/GrMemoryPool.cpp
@@ -7,10 +7,10 @@
#include "GrMemoryPool.h"
#include "SkMalloc.h"
-#ifdef SK_DEBUG
-#include "SkAtomics.h"
-#endif
#include "ops/GrOp.h"
+#ifdef SK_DEBUG
+ #include <atomic>
+#endif
#ifdef SK_DEBUG
#define VALIDATE this->validate()
@@ -89,7 +89,10 @@
// so that we can decrement the live count on delete in constant time.
AllocHeader* allocData = reinterpret_cast<AllocHeader*>(ptr);
SkDEBUGCODE(allocData->fSentinal = kAssignedMarker);
- SkDEBUGCODE(allocData->fID = []{static int32_t gID; return sk_atomic_inc(&gID) + 1;}());
+ SkDEBUGCODE(allocData->fID = []{
+ static std::atomic<int32_t> nextID{1};
+ return nextID++;
+ }());
// You can set a breakpoint here when a leaked ID is allocated to see the stack frame.
SkDEBUGCODE(fAllocatedIDs.add(allocData->fID));
allocData->fHeader = fTail;
diff --git a/src/gpu/GrOpList.cpp b/src/gpu/GrOpList.cpp
index dd889e8..b1ccc82 100644
--- a/src/gpu/GrOpList.cpp
+++ b/src/gpu/GrOpList.cpp
@@ -13,15 +13,13 @@
#include "GrRenderTargetPriv.h"
#include "GrSurfaceProxy.h"
#include "GrTextureProxyPriv.h"
-
-#include "SkAtomics.h"
+#include <atomic>
uint32_t GrOpList::CreateUniqueID() {
- static int32_t gUniqueID = SK_InvalidUniqueID;
+ static std::atomic<uint32_t> nextID{1};
uint32_t id;
- // Loop in case our global wraps around, as we never want to return a 0.
do {
- id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
+ id = nextID++;
} while (id == SK_InvalidUniqueID);
return id;
}
diff --git a/src/gpu/GrProcessor.h b/src/gpu/GrProcessor.h
index b8338b3..8ae9493 100644
--- a/src/gpu/GrProcessor.h
+++ b/src/gpu/GrProcessor.h
@@ -8,7 +8,6 @@
#ifndef GrProcessor_DEFINED
#define GrProcessor_DEFINED
-#include "../private/SkAtomics.h"
#include "GrBuffer.h"
#include "GrColor.h"
#include "GrProcessorUnitTest.h"
diff --git a/src/gpu/GrResourceAllocator.cpp b/src/gpu/GrResourceAllocator.cpp
index eab856f..52aec58 100644
--- a/src/gpu/GrResourceAllocator.cpp
+++ b/src/gpu/GrResourceAllocator.cpp
@@ -19,14 +19,16 @@
#include "GrUninstantiateProxyTracker.h"
#if GR_TRACK_INTERVAL_CREATION
-uint32_t GrResourceAllocator::Interval::CreateUniqueID() {
- static int32_t gUniqueID = SK_InvalidUniqueID;
- uint32_t id;
- do {
- id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
- } while (id == SK_InvalidUniqueID);
- return id;
-}
+ #include <atomic>
+
+ uint32_t GrResourceAllocator::Interval::CreateUniqueID() {
+ static std::atomic<uint32_t> nextID{1};
+ uint32_t id;
+ do {
+ id = nextID++;
+ } while (id == SK_InvalidUniqueID);
+ return id;
+ }
#endif
void GrResourceAllocator::Interval::assign(sk_sp<GrSurface> s) {
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 817d188..ffadc30 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -19,6 +19,7 @@
#include "SkRandom.h"
#include "SkTSort.h"
#include "SkTo.h"
+#include <atomic>
DECLARE_SKMESSAGEBUS_MESSAGE(GrUniqueKeyInvalidatedMessage);
@@ -30,9 +31,9 @@
//////////////////////////////////////////////////////////////////////////////
GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() {
- static int32_t gType = INHERITED::kInvalidDomain + 1;
+ static std::atomic<int32_t> nextType{INHERITED::kInvalidDomain + 1};
- int32_t type = sk_atomic_inc(&gType);
+ int32_t type = nextType++;
if (type > SkTo<int32_t>(UINT16_MAX)) {
SK_ABORT("Too many Resource Types");
}
@@ -41,9 +42,9 @@
}
GrUniqueKey::Domain GrUniqueKey::GenerateDomain() {
- static int32_t gDomain = INHERITED::kInvalidDomain + 1;
+ static std::atomic<int32_t> nextDomain{INHERITED::kInvalidDomain + 1};
- int32_t domain = sk_atomic_inc(&gDomain);
+ int32_t domain = nextDomain++;
if (domain > SkTo<int32_t>(UINT16_MAX)) {
SK_ABORT("Too many GrUniqueKey Domains");
}
diff --git a/src/gpu/ccpr/GrCCAtlas.cpp b/src/gpu/ccpr/GrCCAtlas.cpp
index 6dc523d..a41eb38 100644
--- a/src/gpu/ccpr/GrCCAtlas.cpp
+++ b/src/gpu/ccpr/GrCCAtlas.cpp
@@ -16,6 +16,7 @@
#include "GrTextureProxy.h"
#include "SkMakeUnique.h"
#include "SkMathPriv.h"
+#include <atomic>
class GrCCAtlas::Node {
public:
@@ -154,8 +155,8 @@
}
static uint32_t next_atlas_unique_id() {
- static int32_t nextID;
- return sk_atomic_inc(&nextID);
+ static std::atomic<uint32_t> nextID;
+ return nextID++;
}
const GrUniqueKey& GrCCAtlas::getOrAssignUniqueKey(GrOnFlushResourceProvider* onFlushRP) {
diff --git a/src/gpu/effects/GrSkSLFP.h b/src/gpu/effects/GrSkSLFP.h
index c4acfd0..912ba23 100644
--- a/src/gpu/effects/GrSkSLFP.h
+++ b/src/gpu/effects/GrSkSLFP.h
@@ -16,6 +16,7 @@
#include "SkSLPipelineStageCodeGenerator.h"
#include "SkRefCnt.h"
#include "../private/GrSkSLFPFactoryCache.h"
+#include <atomic>
#if GR_TEST_UTILS
#define GR_FP_SRC_STRING const char*
@@ -33,8 +34,8 @@
* NewIndex once, statically, and use this index for all calls to Make.
*/
static int NewIndex() {
- static int index = 0;
- return sk_atomic_inc(&index);
+ static std::atomic<int> nextIndex{0};
+ return nextIndex++;
}
/**
diff --git a/src/gpu/ops/GrOp.cpp b/src/gpu/ops/GrOp.cpp
index 3a36d73..b8a0031 100644
--- a/src/gpu/ops/GrOp.cpp
+++ b/src/gpu/ops/GrOp.cpp
@@ -7,9 +7,8 @@
#include "GrOp.h"
-int32_t GrOp::gCurrOpClassID = GrOp::kIllegalOpID;
-
-int32_t GrOp::gCurrOpUniqueID = GrOp::kIllegalOpID;
+std::atomic<uint32_t> GrOp::gCurrOpClassID {GrOp::kIllegalOpID + 1};
+std::atomic<uint32_t> GrOp::gCurrOpUniqueID{GrOp::kIllegalOpID + 1};
#ifdef SK_DEBUG
void* GrOp::operator new(size_t size) {
diff --git a/src/gpu/ops/GrOp.h b/src/gpu/ops/GrOp.h
index 8cf05a8..f3d0db0 100644
--- a/src/gpu/ops/GrOp.h
+++ b/src/gpu/ops/GrOp.h
@@ -8,8 +8,6 @@
#ifndef GrOp_DEFINED
#define GrOp_DEFINED
-#include <new>
-#include "../private/SkAtomics.h"
#include "GrGpuResource.h"
#include "GrNonAtomicRef.h"
#include "GrTracing.h"
@@ -17,6 +15,8 @@
#include "SkMatrix.h"
#include "SkRect.h"
#include "SkString.h"
+#include <atomic>
+#include <new>
class GrCaps;
class GrGpuCommandBuffer;
@@ -303,11 +303,9 @@
// Otherwise, this op's bounds.
virtual void onExecute(GrOpFlushState*, const SkRect& chainBounds) = 0;
- static uint32_t GenID(int32_t* idCounter) {
- // The atomic inc returns the old value not the incremented value. So we add
- // 1 to the returned value.
- uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1;
- if (!id) {
+ static uint32_t GenID(std::atomic<uint32_t>* idCounter) {
+ uint32_t id = (*idCounter)++;
+ if (id == 0) {
SK_ABORT("This should never wrap as it should only be called once for each GrOp "
"subclass.");
}
@@ -339,8 +337,8 @@
mutable uint32_t fUniqueID = SK_InvalidUniqueID;
SkRect fBounds;
- static int32_t gCurrOpUniqueID;
- static int32_t gCurrOpClassID;
+ static std::atomic<uint32_t> gCurrOpUniqueID;
+ static std::atomic<uint32_t> gCurrOpClassID;
};
#endif
diff --git a/src/gpu/vk/GrVkSampler.h b/src/gpu/vk/GrVkSampler.h
index 9d74d8f..dce9ef9 100644
--- a/src/gpu/vk/GrVkSampler.h
+++ b/src/gpu/vk/GrVkSampler.h
@@ -12,9 +12,9 @@
#include "GrVkResource.h"
#include "GrVkSamplerYcbcrConversion.h"
-#include "SkAtomics.h"
#include "SkOpts.h"
#include "vk/GrVkTypes.h"
+#include <atomic>
class GrSamplerState;
class GrVkGpu;
@@ -71,10 +71,10 @@
void abandonGPUData() const override;
static uint32_t GenID() {
- static int32_t gUniqueID = SK_InvalidUniqueID;
+ static std::atomic<uint32_t> nextID{1};
uint32_t id;
do {
- id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
+ id = nextID++;
} while (id == SK_InvalidUniqueID);
return id;
}
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp
index e4a1986..c51ce9b 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -5,13 +5,12 @@
* found in the LICENSE file.
*/
-#include "SkAtomics.h"
+#include "GrBackendSurface.h"
#include "SkCanvas.h"
#include "SkFontLCDConfig.h"
#include "SkImagePriv.h"
#include "SkSurface_Base.h"
-
-#include "GrBackendSurface.h"
+#include <atomic>
static SkPixelGeometry compute_default_geometry() {
SkFontLCDConfig::LCDOrder order = SkFontLCDConfig::GetSubpixelOrder();
@@ -122,8 +121,8 @@
uint32_t SkSurface_Base::newGenerationID() {
SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this);
- static int32_t gID;
- return sk_atomic_inc(&gID) + 1;
+ static std::atomic<uint32_t> nextID{1};
+ return nextID++;
}
static SkSurface_Base* asSB(SkSurface* surface) {
diff --git a/src/shaders/SkPictureShader.cpp b/src/shaders/SkPictureShader.cpp
index 3a48c32..1601ab9 100644
--- a/src/shaders/SkPictureShader.cpp
+++ b/src/shaders/SkPictureShader.cpp
@@ -7,7 +7,6 @@
#include "SkPictureShader.h"
-#include "SkAtomics.h"
#include "SkArenaAlloc.h"
#include "SkBitmap.h"
#include "SkBitmapProcShader.h"
@@ -19,6 +18,7 @@
#include "SkPicturePriv.h"
#include "SkReadBuffer.h"
#include "SkResourceCache.h"
+#include <atomic>
#if SK_SUPPORT_GPU
#include "GrCaps.h"
@@ -94,13 +94,14 @@
}
};
-static int32_t gNextID = 1;
uint32_t next_id() {
- int32_t id;
+ static std::atomic<uint32_t> nextID{1};
+
+ uint32_t id;
do {
- id = sk_atomic_inc(&gNextID);
+ id = nextID++;
} while (id == SK_InvalidGenID);
- return static_cast<uint32_t>(id);
+ return id;
}
} // namespace
diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp
index e4aab42..0ff350a 100644
--- a/tests/ProcessorTest.cpp
+++ b/tests/ProcessorTest.cpp
@@ -23,6 +23,7 @@
#include "ops/GrRectOpFactory.h"
#include "TestUtils.h"
+#include <atomic>
#include <random>
namespace {
@@ -84,9 +85,8 @@
const char* name() const override { return "test"; }
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
- // We don't really care about reusing these.
- static int32_t gKey = 0;
- b->add32(sk_atomic_inc(&gKey));
+ static std::atomic<int32_t> nextKey{0};
+ b->add32(nextKey++);
}
std::unique_ptr<GrFragmentProcessor> clone() const override {
diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp
index 99f9609..5d3169b 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -6,10 +6,11 @@
*/
#include "CrashHandler.h"
+#include "GrContext.h"
+#include "GrContextFactory.h"
#include "OverwriteLine.h"
#include "PathOpsDebug.h"
#include "Resources.h"
-#include "SkAtomics.h"
#include "SkCommonFlags.h"
#include "SkGraphics.h"
#include "SkOSFile.h"
@@ -19,9 +20,7 @@
#include "SkTemplates.h"
#include "SkTime.h"
#include "Test.h"
-
-#include "GrContext.h"
-#include "GrContextFactory.h"
+#include <atomic>
using namespace skiatest;
using namespace sk_gpu_test;
@@ -50,10 +49,8 @@
bool success,
SkMSec elapsed,
int testCount) {
- const int done = 1 + sk_atomic_inc(&fDone);
- for (int i = 0; i < testCount; ++i) {
- sk_atomic_inc(&fTestCount);
- }
+ const int done = ++fDone;
+ fTestCount += testCount;
if (!success) {
SkDebugf("\n---- %s FAILED", testName);
}
@@ -68,15 +65,15 @@
testName);
}
- void reportFailure() { sk_atomic_inc(&fFailCount); }
+ void reportFailure() { fFailCount++; }
int32_t testCount() { return fTestCount; }
int32_t failCount() { return fFailCount; }
private:
- int32_t fDone; // atomic
- int32_t fTestCount; // atomic
- int32_t fFailCount; // atomic
+ std::atomic<int32_t> fDone;
+ std::atomic<int32_t> fTestCount;
+ std::atomic<int32_t> fFailCount;
const int fTotal;
};