vlog("done %s\n", id.c_str());
int pending;
{
- SkAutoTAcquire<SkSpinlock> lock(gMutex);
+ SkAutoMutexAcquire lock(gMutex);
for (int i = 0; i < gRunning.count(); i++) {
if (gRunning[i] == id) {
gRunning.removeShuffle(i);
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);
vlog("start %s\n", id.c_str());
- SkAutoTAcquire<SkSpinlock> lock(gMutex);
+ SkAutoMutexAcquire lock(gMutex);
gRunning.push_back(id);
}
peak = sk_tools::getMaxResidentSetSizeMB();
SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs);
- SkAutoTAcquire<SkSpinlock> lock(gMutex);
+ SkAutoMutexAcquire lock(gMutex);
info("\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) {
#undef _
};
- SkAutoTAcquire<SkSpinlock> lock(gMutex);
+ SkAutoMutexAcquire lock(gMutex);
const DWORD code = e->ExceptionRecord->ExceptionCode;
info("\nCaught exception %u", code);
#include <stdlib.h>
static void crash_handler(int sig) {
- SkAutoTAcquire<SkSpinlock> lock(gMutex);
+ SkAutoMutexAcquire lock(gMutex);
info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig));
for (auto& task : gRunning) {
if (src->veto(sink->flags()) ||
is_blacklisted(sink.tag.c_str(), src.tag.c_str(),
src.options.c_str(), src->name().c_str())) {
- SkAutoTAcquire<SkSpinlock> lock(gMutex);
+ SkAutoMutexAcquire lock(gMutex);
gPending--;
continue;
}
~SkMutex() { fSemaphore.cleanup(); }
};
-template <typename Lock>
-class SkAutoTAcquire : SkNoncopyable {
+class SkAutoMutexAcquire {
public:
- explicit SkAutoTAcquire(Lock& mutex) : fMutex(&mutex) {
- SkASSERT(fMutex != nullptr);
- mutex.acquire();
- }
-
- explicit SkAutoTAcquire(Lock* mutex) : fMutex(mutex) {
+ template <typename T>
+ SkAutoMutexAcquire(T* mutex) : fMutex(mutex) {
if (mutex) {
mutex->acquire();
}
+ fRelease = [](void* mutex) { ((T*)mutex)->release(); };
}
- /** If the mutex has not been released, release it now. */
- ~SkAutoTAcquire() {
- if (fMutex) {
- fMutex->release();
- }
- }
+ template <typename T>
+ SkAutoMutexAcquire(T& mutex) : SkAutoMutexAcquire(&mutex) {}
+
+ ~SkAutoMutexAcquire() { this->release(); }
- /** If the mutex has not been released, release it now. */
void release() {
if (fMutex) {
- fMutex->release();
- fMutex = nullptr;
+ fRelease(fMutex);
}
- }
-
- /** Assert that we're holding the mutex. */
- void assertHeld() {
- SkASSERT(fMutex);
- fMutex->assertHeld();
+ fMutex = nullptr;
}
private:
- Lock* fMutex;
+ void* fMutex;
+ void (*fRelease)(void*);
};
+#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire)
-// SkAutoTExclusive is a lighter weight version of SkAutoTAcquire. It assumes that there is a valid
-// mutex, thus removing the check for the null pointer.
-template <typename Lock>
-class SkAutoTExclusive {
+// SkAutoExclusive is a lighter weight version of SkAutoMutexAcquire.
+// It assumes that there is a valid mutex, obviating the null check.
+class SkAutoExclusive {
public:
- SkAutoTExclusive(Lock& lock) : fLock(lock) { lock.acquire(); }
- ~SkAutoTExclusive() { fLock.release(); }
-private:
- Lock &fLock;
-};
+ template <typename T>
+ SkAutoExclusive(T& mutex) : fMutex(&mutex) {
+ mutex.acquire();
-typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire;
-#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire)
+ fRelease = [](void* mutex) { ((T*)mutex)->release(); };
+ }
+ ~SkAutoExclusive() { fRelease(fMutex); }
-typedef SkAutoTExclusive<SkBaseMutex> SkAutoMutexExclusive;
-#define SkAutoMutexExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexExclusive)
+private:
+ void* fMutex;
+ void (*fRelease)(void*);
+};
+#define SkAutoExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoExclusive)
#endif//SkMutex_DEFINED
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-typedef SkAutoTExclusive<SkSpinlock> Exclusive;
-
size_t SkGlyphCache_Globals::setCacheSizeLimit(size_t newLimit) {
static const size_t minLimit = 256 * 1024;
if (newLimit < minLimit) {
newLimit = minLimit;
}
- Exclusive ac(fLock);
+ SkAutoExclusive ac(fLock);
size_t prevLimit = fCacheSizeLimit;
fCacheSizeLimit = newLimit;
newCount = 0;
}
- Exclusive ac(fLock);
+ SkAutoExclusive ac(fLock);
int prevCount = fCacheCountLimit;
fCacheCountLimit = newCount;
}
void SkGlyphCache_Globals::purgeAll() {
- Exclusive ac(fLock);
+ SkAutoExclusive ac(fLock);
this->internalPurge(fTotalMemoryUsed);
}
SkGlyphCache* cache;
{
- Exclusive ac(globals.fLock);
+ SkAutoExclusive ac(globals.fLock);
globals.validate();
void SkGlyphCache::VisitAll(Visitor visitor, void* context) {
SkGlyphCache_Globals& globals = get_globals();
- Exclusive ac(globals.fLock);
+ SkAutoExclusive ac(globals.fLock);
SkGlyphCache* cache;
globals.validate();
///////////////////////////////////////////////////////////////////////////////
void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) {
- Exclusive ac(fLock);
+ SkAutoExclusive ac(fLock);
this->validate();
cache->validate();
*/
static SkSharedMutex DWriteFactoryMutex;
-typedef SkAutoTExclusive<SkSharedMutex> Exclusive;
typedef SkAutoSharedMutexShared Shared;
static bool isLCD(const SkScalerContext::Rec& rec) {
}
static bool is_hinted_without_gasp(DWriteFontTypeface* typeface) {
- Exclusive l(DWriteFactoryMutex);
+ SkAutoExclusive l(DWriteFactoryMutex);
AutoTDWriteTable<SkOTTableMaximumProfile> maxp(typeface->fDWriteFontFace.get());
if (!maxp.fExists) {
return false;
}
static bool has_bitmap_strike(DWriteFontTypeface* typeface, PPEMRange range) {
- Exclusive l(DWriteFactoryMutex);
+ SkAutoExclusive l(DWriteFactoryMutex);
{
AutoTDWriteTable<SkOTTableEmbeddedBitmapLocation> eblc(typeface->fDWriteFontFace.get());
if (!eblc.fExists) {
if (DWRITE_MEASURING_MODE_GDI_CLASSIC == fMeasuringMode ||
DWRITE_MEASURING_MODE_GDI_NATURAL == fMeasuringMode)
{
- Exclusive l(DWriteFactoryMutex);
+ SkAutoExclusive l(DWriteFactoryMutex);
HRVM(fTypeface->fDWriteFontFace->GetGdiCompatibleGlyphMetrics(
fTextSizeMeasure,
1.0f, // pixelsPerDip
&gm),
"Could not get gdi compatible glyph metrics.");
} else {
- Exclusive l(DWriteFactoryMutex);
+ SkAutoExclusive l(DWriteFactoryMutex);
HRVM(fTypeface->fDWriteFontFace->GetDesignGlyphMetrics(&glyphId, 1, &gm),
"Could not get design metrics.");
}
SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
{
- Exclusive l(DWriteFactoryMutex);
+ SkAutoExclusive l(DWriteFactoryMutex);
HRM(fTypeface->fFactory->CreateGlyphRunAnalysis(
&run,
1.0f, // pixelsPerDip,
SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
{
- Exclusive l(DWriteFactoryMutex);
+ SkAutoExclusive l(DWriteFactoryMutex);
HRNM(fTypeface->fFactory->CreateGlyphRunAnalysis(&run,
1.0f, // pixelsPerDip,
&fXform,
HRVM(SkDWriteGeometrySink::Create(&path, &geometryToPath),
"Could not create geometry to path converter.");
{
- Exclusive l(DWriteFactoryMutex);
+ SkAutoExclusive l(DWriteFactoryMutex);
HRVM(colorGlyph->glyphRun.fontFace->GetGlyphRunOutline(
colorGlyph->glyphRun.fontEmSize,
colorGlyph->glyphRun.glyphIndices,
"Could not create geometry to path converter.");
uint16_t glyphId = glyph.getGlyphID();
{
- Exclusive l(DWriteFactoryMutex);
+ SkAutoExclusive l(DWriteFactoryMutex);
//TODO: convert to<->from DIUs? This would make a difference if hinting.
//It may not be needed, it appears that DirectWrite only hints at em size.
HRVM(fTypeface->fDWriteFontFace->GetGlyphRunOutline(SkScalarToFloat(fTextSizeRender),