From 5e56cfd3fa1041dbb83899844fb92fa9a2ef1009 Mon Sep 17 00:00:00 2001 From: mtklein Date: Wed, 4 May 2016 15:21:12 -0700 Subject: [PATCH] SK_DECLARE_STATIC_MUTEX -> static SkMutex There's no need to use a macro to declare static SkMutexes any more (and there's likewise no need to restrict them to global scope). BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1948193002 Review-Url: https://codereview.chromium.org/1948193002 --- dm/DM.cpp | 2 +- dm/DMJsonWriter.cpp | 4 ++-- include/private/SkMutex.h | 3 --- src/core/SkDeviceProfile.cpp | 2 +- src/core/SkPaint.cpp | 2 +- src/core/SkResourceCache.cpp | 2 +- src/core/SkTypeface.cpp | 2 +- src/core/SkTypefaceCache.cpp | 2 +- src/effects/gradients/SkGradientShader.cpp | 2 +- src/fonts/SkTestScalerContext.cpp | 2 +- src/lazy/SkDiscardableMemoryPool.cpp | 2 +- src/pathops/SkPathOpsDebug.cpp | 12 ++++++------ src/pathops/SkPathOpsOp.cpp | 6 +++--- src/ports/SkFontConfigInterface_direct.cpp | 2 +- src/ports/SkFontHost_FreeType.cpp | 2 +- src/ports/SkFontHost_fontconfig.cpp | 2 +- src/ports/SkFontHost_mac.cpp | 4 ++-- src/ports/SkFontMgr_fontconfig.cpp | 2 +- src/ports/SkTLS_win.cpp | 2 +- src/views/SkEventSink.cpp | 2 +- tests/PathOpsExtendedTest.cpp | 6 +++--- .../command_buffer/GLTestContext_command_buffer.cpp | 2 +- tools/sk_tool_utils_font.cpp | 2 +- 23 files changed, 33 insertions(+), 36 deletions(-) diff --git a/dm/DM.cpp b/dm/DM.cpp index 9dbd43adda..0cf649e9d6 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -104,7 +104,7 @@ static void info(const char* fmt) { } } -SK_DECLARE_STATIC_MUTEX(gFailuresMutex); +static SkMutex gFailuresMutex; static SkTArray gFailures; static void fail(const SkString& err) { diff --git a/dm/DMJsonWriter.cpp b/dm/DMJsonWriter.cpp index 7bd8acd6d2..652c70b8cc 100644 --- a/dm/DMJsonWriter.cpp +++ b/dm/DMJsonWriter.cpp @@ -19,7 +19,7 @@ namespace DM { SkTArray gBitmapResults; -SK_DECLARE_STATIC_MUTEX(gBitmapResultLock); +static SkMutex gBitmapResultLock; void JsonWriter::AddBitmapResult(const BitmapResult& result) { SkAutoMutexAcquire lock(&gBitmapResultLock); @@ -27,7 +27,7 @@ void JsonWriter::AddBitmapResult(const BitmapResult& result) { } SkTArray gFailures; -SK_DECLARE_STATIC_MUTEX(gFailureLock); +static SkMutex gFailureLock; void JsonWriter::AddTestFailure(const skiatest::Failure& failure) { SkAutoMutexAcquire lock(gFailureLock); diff --git a/include/private/SkMutex.h b/include/private/SkMutex.h index b9af00f8a8..503b1e8efc 100644 --- a/include/private/SkMutex.h +++ b/include/private/SkMutex.h @@ -12,9 +12,6 @@ #include "../private/SkThreadID.h" #include "SkTypes.h" -// TODO: no need for this anymore. -#define SK_DECLARE_STATIC_MUTEX(name) static SkMutex name; - class SkMutex { public: constexpr SkMutex() = default; diff --git a/src/core/SkDeviceProfile.cpp b/src/core/SkDeviceProfile.cpp index e1c10c87d7..272a710b2f 100644 --- a/src/core/SkDeviceProfile.cpp +++ b/src/core/SkDeviceProfile.cpp @@ -44,7 +44,7 @@ SkDeviceProfile* SkDeviceProfile::Create(float gammaExp, return new SkDeviceProfile(gammaExp, contrast, config, level); } -SK_DECLARE_STATIC_MUTEX(gMutex); +static SkMutex gMutex; static SkDeviceProfile* gDefaultProfile; static SkDeviceProfile* gGlobalProfile; diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 67bbda1665..c9fff0d3c2 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1457,7 +1457,7 @@ void SkScalerContext::MakeRec(const SkPaint& paint, * cachedMaskGamma the caller must hold the gMaskGammaCacheMutex and continue * to hold it until the returned pointer is refed or forgotten. */ -SK_DECLARE_STATIC_MUTEX(gMaskGammaCacheMutex); +static SkMutex gMaskGammaCacheMutex; static SkMaskGamma* gLinearMaskGamma = nullptr; static SkMaskGamma* gMaskGamma = nullptr; diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp index e465132288..bab3dd707b 100644 --- a/src/core/SkResourceCache.cpp +++ b/src/core/SkResourceCache.cpp @@ -542,7 +542,7 @@ void SkResourceCache::checkMessages() { /////////////////////////////////////////////////////////////////////////////// -SK_DECLARE_STATIC_MUTEX(gMutex); +static SkMutex gMutex; static SkResourceCache* gResourceCache = nullptr; /** Must hold gMutex when calling. */ diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 75bb05c2b1..1788759e3d 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -78,7 +78,7 @@ protected: } -SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex); +static SkMutex gCreateDefaultMutex; SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { static SkOnce once[4]; diff --git a/src/core/SkTypefaceCache.cpp b/src/core/SkTypefaceCache.cpp index 05a7a8eb5f..8c53b7fc27 100644 --- a/src/core/SkTypefaceCache.cpp +++ b/src/core/SkTypefaceCache.cpp @@ -64,7 +64,7 @@ SkFontID SkTypefaceCache::NewFontID() { return sk_atomic_inc(&gFontID) + 1; } -SK_DECLARE_STATIC_MUTEX(gMutex); +static SkMutex gMutex; void SkTypefaceCache::Add(SkTypeface* face) { SkAutoMutexAcquire ama(gMutex); diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index fdb6e59e1c..ffcbfdd9d2 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -625,7 +625,7 @@ SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::refCache(U8CPU return fCache; } -SK_DECLARE_STATIC_MUTEX(gGradientCacheMutex); +static SkMutex gGradientCacheMutex; /* * Because our caller might rebuild the same (logically the same) gradient * over and over, we'd like to return exactly the same "bitmap" if possible, diff --git a/src/fonts/SkTestScalerContext.cpp b/src/fonts/SkTestScalerContext.cpp index a2748564a5..f59bb0f8e6 100644 --- a/src/fonts/SkTestScalerContext.cpp +++ b/src/fonts/SkTestScalerContext.cpp @@ -43,7 +43,7 @@ SkTestFont::~SkTestFont() { #ifdef SK_DEBUG #include "SkMutex.h" -SK_DECLARE_STATIC_MUTEX(gUsedCharsMutex); +static SkMutex gUsedCharsMutex; #endif diff --git a/src/lazy/SkDiscardableMemoryPool.cpp b/src/lazy/SkDiscardableMemoryPool.cpp index d6753def9d..da7db52958 100644 --- a/src/lazy/SkDiscardableMemoryPool.cpp +++ b/src/lazy/SkDiscardableMemoryPool.cpp @@ -244,7 +244,7 @@ SkDiscardableMemoryPool* SkDiscardableMemoryPool::Create(size_t size, SkMutex* m return new DiscardableMemoryPool(size, mutex); } -SK_DECLARE_STATIC_MUTEX(gMutex); +static SkMutex gMutex; SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { static SkOnce once; diff --git a/src/pathops/SkPathOpsDebug.cpp b/src/pathops/SkPathOpsDebug.cpp index 546771e84c..1ee7b38e18 100644 --- a/src/pathops/SkPathOpsDebug.cpp +++ b/src/pathops/SkPathOpsDebug.cpp @@ -267,7 +267,7 @@ static void show_op(SkPathOp op, const char* pathOne, const char* pathTwo) { SkDebugf("}\n"); } -SK_DECLARE_STATIC_MUTEX(gTestMutex); +static SkMutex gTestMutex; void SkPathOpsDebug::ShowPath(const SkPath& a, const SkPath& b, SkPathOp shapeOp, const char* testName) { @@ -646,7 +646,7 @@ void SkOpSegment::debugMissingCoincidence(const char* id, SkPathOpsDebug::Glitch } if (spanBase->segment() != opp && spanBase->containsCoinEnd(opp)) { continue; - } + } const SkOpPtT* priorPtT = nullptr, * priorStopPtT; // find prior span containing opp segment const SkOpSegment* priorOpp = nullptr; @@ -786,11 +786,11 @@ void SkOpSegment::debugMoveMultiples(const char* id, SkPathOpsDebug::GlitchLog* } goto checkNextSpan; } - tryNextSpan: + tryNextSpan: ; } while (oppTest != oppLast && (oppTest = oppTest->upCast()->next())); } while ((testPtT = testPtT->next()) != startPtT); -checkNextSpan: +checkNextSpan: ; } while ((test = test->final() ? nullptr : test->upCast()->next())); } @@ -958,7 +958,7 @@ void SkOpSegment::debugShowNewWinding(const char* fun, const SkOpSpan* span, int // loop looking for a pair of angle parts that are too close to be sorted /* This is called after other more simple intersection and angle sorting tests have been exhausted. This should be rarely called -- the test below is thorough and time consuming. - This checks the distance between start points; the distance between + This checks the distance between start points; the distance between */ #if DEBUG_ANGLE void SkOpAngle::debugCheckNearCoincidence() const { @@ -996,7 +996,7 @@ void SkOpAngle::debugCheckNearCoincidence() const { SkDebugf("\n"); } test = test->fNext; - } while (test->fNext != this); + } while (test->fNext != this); } #endif diff --git a/src/pathops/SkPathOpsOp.cpp b/src/pathops/SkPathOpsOp.cpp index 257cb8ee69..545d696a36 100644 --- a/src/pathops/SkPathOpsOp.cpp +++ b/src/pathops/SkPathOpsOp.cpp @@ -223,7 +223,7 @@ static void dump_op(const SkPath& one, const SkPath& two, SkPathOp op) { dump_path(file, two, false, true); fprintf(file, " SkPath path2(path);\n"); fprintf(file, " testPathOp(reporter, path1, path2, (SkPathOp) %d, filename);\n", op); - fprintf(file, "}\n"); + fprintf(file, "}\n"); fclose(file); } #endif @@ -233,7 +233,7 @@ static void dump_op(const SkPath& one, const SkPath& two, SkPathOp op) { #include "SkMutex.h" -SK_DECLARE_STATIC_MUTEX(debugWorstLoop); +static SkMutex debugWorstLoop; SkOpGlobalState debugWorstState(nullptr, nullptr SkDEBUGPARAMS(nullptr)); @@ -254,7 +254,7 @@ bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result, SkOpGlobalState globalState(&coincidence, contourList SkDEBUGPARAMS(testName)); #if DEBUGGING_PATHOPS_FROM_HOST dump_op(one, two, op); -#endif +#endif #if 0 && DEBUG_SHOW_TEST_NAME char* debugName = DEBUG_FILENAME_STRING; if (debugName && debugName[0]) { diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp index d6fa96a46c..f2360020ad 100644 --- a/src/ports/SkFontConfigInterface_direct.cpp +++ b/src/ports/SkFontConfigInterface_direct.cpp @@ -32,7 +32,7 @@ namespace { // Fontconfig is not threadsafe before 2.10.91. Before that, we lock with a global mutex. // See https://bug.skia.org/1497 for background. -SK_DECLARE_STATIC_MUTEX(gFCMutex); +static SkMutex gFCMutex; #ifdef SK_DEBUG void* CreateThreadFcLocked() { return new bool(false); } diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index b53364eacb..1cde6cbfbf 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -145,7 +145,7 @@ private: struct SkFaceRec; -SK_DECLARE_STATIC_MUTEX(gFTMutex); +static SkMutex gFTMutex; static FreeTypeLibrary* gFTLibrary; static SkFaceRec* gFaceRecHead; diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp index 0ffc26116f..416173add9 100644 --- a/src/ports/SkFontHost_fontconfig.cpp +++ b/src/ports/SkFontHost_fontconfig.cpp @@ -10,7 +10,7 @@ #include "SkMutex.h" #include "SkRefCnt.h" -SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex); +static SkMutex gFontConfigInterfaceMutex; static SkFontConfigInterface* gFontConfigInterface; SkFontConfigInterface* SkFontConfigInterface::RefGlobal() { diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 8593b39611..6f0bbad6bd 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -54,7 +54,7 @@ #define USE_GLOBAL_MUTEX_FOR_CG_ACCESS #ifdef USE_GLOBAL_MUTEX_FOR_CG_ACCESS - SK_DECLARE_STATIC_MUTEX(gCGMutex); + static SkMutex gCGMutex; #define AUTO_CG_LOCK() SkAutoMutexAcquire amc(gCGMutex) #else #define AUTO_CG_LOCK() @@ -550,7 +550,7 @@ static SkTypeface* NewFromName(const char familyName[], const SkFontStyle& theSt return face; } -SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); +static SkMutex gGetDefaultFaceMutex; static SkTypeface* GetDefaultFace() { SkAutoMutexAcquire ma(gGetDefaultFaceMutex); diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index 610a3001fb..32f10a491c 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -62,7 +62,7 @@ namespace { // Fontconfig is not threadsafe before 2.10.91. Before that, we lock with a global mutex. // See https://bug.skia.org/1497 for background. -SK_DECLARE_STATIC_MUTEX(gFCMutex); +static SkMutex gFCMutex; #ifdef SK_DEBUG void* CreateThreadFcLocked() { return new bool(false); } diff --git a/src/ports/SkTLS_win.cpp b/src/ports/SkTLS_win.cpp index 8bc55a0f2c..3f00842408 100644 --- a/src/ports/SkTLS_win.cpp +++ b/src/ports/SkTLS_win.cpp @@ -12,7 +12,7 @@ static bool gOnce = false; static DWORD gTlsIndex; -SK_DECLARE_STATIC_MUTEX(gMutex); +static SkMutex gMutex; void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) { if (!forceCreateTheSlot && !gOnce) { diff --git a/src/views/SkEventSink.cpp b/src/views/SkEventSink.cpp index 1464fa0fac..5345608969 100644 --- a/src/views/SkEventSink.cpp +++ b/src/views/SkEventSink.cpp @@ -257,7 +257,7 @@ SkEventSink* SkEventSink::FindSink(SkEventSinkID sinkID) #include "SkTDict.h" #define kMinStringBufferSize 128 -SK_DECLARE_STATIC_MUTEX(gNamedSinkMutex); +static SkMutex gNamedSinkMutex; static SkTDict gNamedSinkIDs(kMinStringBufferSize); /** Register a name/id pair with the system. If the name already exists, diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp index c96cbcdae5..27baa8c4b8 100644 --- a/tests/PathOpsExtendedTest.cpp +++ b/tests/PathOpsExtendedTest.cpp @@ -331,7 +331,7 @@ void ShowTestArray(const char* testName) { } } -SK_DECLARE_STATIC_MUTEX(compareDebugOut3); +static SkMutex compareDebugOut3; static int comparePaths(skiatest::Reporter* reporter, const char* testName, const SkPath& one, const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkBitmap& bitmap, @@ -419,7 +419,7 @@ static void outputToStream(const char* pathStr, const char* pathPrefix, const ch outFile.flush(); } -SK_DECLARE_STATIC_MUTEX(simplifyDebugOut); +static SkMutex simplifyDebugOut; bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& state, const char* pathStr) { @@ -578,7 +578,7 @@ bool testPathFailOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& return true; } -SK_DECLARE_STATIC_MUTEX(gMutex); +static SkMutex gMutex; void initializeTests(skiatest::Reporter* reporter, const char* test) { #if 0 // doesn't work yet diff --git a/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp b/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp index 850adaaf25..a6f62f0028 100644 --- a/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp +++ b/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp @@ -142,7 +142,7 @@ static const GrGLInterface* create_command_buffer_interface() { // We use a poor man's garbage collector of EGLDisplays. They are only // terminated when there are no more EGLDisplays in use. See crbug.com/603223 -SK_DECLARE_STATIC_MUTEX(gDisplayMutex); +static SkMutex gDisplayMutex; static int gActiveDisplayCnt; SkTArray gRetiredDisplays; diff --git a/tools/sk_tool_utils_font.cpp b/tools/sk_tool_utils_font.cpp index adbfa1692b..67f86d1bb6 100644 --- a/tools/sk_tool_utils_font.cpp +++ b/tools/sk_tool_utils_font.cpp @@ -27,7 +27,7 @@ void release_portable_typefaces() { } } -SK_DECLARE_STATIC_MUTEX(gTestFontMutex); +static SkMutex gTestFontMutex; SkTypeface* create_font(const char* name, SkTypeface::Style style) { SkTestFontData* fontData = nullptr;