aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/private/SkSpinlock.h
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2016-10-20 15:34:06 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-10-20 20:47:33 +0000
commit7c2114fc2f138f210aaed47059888658bb2b297a (patch)
tree5425bd66860363d9700da500056fe1c307024d06 /include/private/SkSpinlock.h
parentbbf251bf225489a0939fff6df938035a290f4d16 (diff)
Cache GrColorSpaceXforms
Even with a modest cache, we're going to get nearly 100% hit rate for typical usage scenarios. I'm hoping to avoid the special case caching of sRGB -> destination, and just rely on the more general mechanism. Yes, this is yet-another cache class. I wanted to use one of many that are laying around, but couldn't find a good fit. On the plus side, it's not much code. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3726 Change-Id: I943be5c99f0d691a87ffe8c5bc3067a8eb491fc2 Reviewed-on: https://skia-review.googlesource.com/3726 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'include/private/SkSpinlock.h')
-rw-r--r--include/private/SkSpinlock.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/private/SkSpinlock.h b/include/private/SkSpinlock.h
index a5d378289f..669a926c7e 100644
--- a/include/private/SkSpinlock.h
+++ b/include/private/SkSpinlock.h
@@ -23,6 +23,16 @@ public:
}
}
+ // Acquire the lock or fail (quickly). Lets the caller decide to do something other than wait.
+ bool tryAcquire() {
+ // To act as a mutex, we need an acquire barrier when we acquire the lock.
+ if (fLocked.exchange(true, std::memory_order_acquire)) {
+ // Lock was contended. Let the caller decide what to do.
+ return false;
+ }
+ return true;
+ }
+
void release() {
// To act as a mutex, we need a release barrier when we release the lock.
fLocked.store(false, std::memory_order_release);