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/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;
}