use acquire/release in SkEventTracer.cpp

BUG=chromium:437044

Review URL: https://codereview.chromium.org/1091283006
This commit is contained in:
mtklein 2015-04-22 20:30:12 -07:00 committed by Commit bot
parent 473ffa179a
commit 743be194ed

View File

@ -41,18 +41,15 @@ class SkDefaultEventTracer : public SkEventTracer {
static SkEventTracer* gUserTracer = nullptr; static SkEventTracer* gUserTracer = nullptr;
SK_DECLARE_STATIC_LAZY_PTR(SkDefaultEventTracer, gDefaultTracer); SK_DECLARE_STATIC_LAZY_PTR(SkDefaultEventTracer, gDefaultTracer);
// We can use relaxed memory order for gUserTracer loads and stores.
// It's not guarding anything but itself.
void SkEventTracer::SetInstance(SkEventTracer* tracer) { void SkEventTracer::SetInstance(SkEventTracer* tracer) {
SkASSERT(nullptr == sk_atomic_load(&gUserTracer, sk_memory_order_relaxed)); SkASSERT(nullptr == sk_atomic_load(&gUserTracer, sk_memory_order_acquire));
sk_atomic_store(&gUserTracer, tracer, sk_memory_order_relaxed); sk_atomic_store(&gUserTracer, tracer, sk_memory_order_release);
// An atomic load during process shutdown is probably overkill, but safe overkill. // An atomic load during process shutdown is probably overkill, but safe overkill.
atexit([](){ SkDELETE(sk_atomic_load(&gUserTracer, sk_memory_order_relaxed)); }); atexit([](){ SkDELETE(sk_atomic_load(&gUserTracer, sk_memory_order_acquire)); });
} }
SkEventTracer* SkEventTracer::GetInstance() { SkEventTracer* SkEventTracer::GetInstance() {
if (SkEventTracer* tracer = sk_atomic_load(&gUserTracer, sk_memory_order_relaxed)) { if (SkEventTracer* tracer = sk_atomic_load(&gUserTracer, sk_memory_order_acquire)) {
return tracer; return tracer;
} }
return gDefaultTracer.get(); return gDefaultTracer.get();