aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-07-09 10:51:36 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-09 10:51:36 -0700
commit828877d7267bcb7c272a1df4e36a6a79894bf00d (patch)
tree3318a7c52ab29d10887412dc2e6733e5d99f506f /include
parentaf4edf9ccc274bef118b268145e0d1ae25072a5f (diff)
Outline SkSpinlock::acquire().
The proportion of time spent doing useful work is well over 99% in acquire(), so outlining it doesn't hurt speed at all, and makes it much easier to pick out on a profile. It'd be about 50/50 work/overhead if we outlined the extremely-cheap release(). I also tried outlining some SkRefCnt methods with similar mixed results. BUG=skia: No public API changes. TBR=reed@google.com Review URL: https://codereview.chromium.org/1212253013
Diffstat (limited to 'include')
-rw-r--r--include/core/SkSpinlock.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/include/core/SkSpinlock.h b/include/core/SkSpinlock.h
index 68a6ff7b12..6edfdf0367 100644
--- a/include/core/SkSpinlock.h
+++ b/include/core/SkSpinlock.h
@@ -15,16 +15,23 @@
#define SK_DECLARE_STATIC_SPINLOCK(name) namespace {} static SkPODSpinlock name
// This class has no constructor and must be zero-initialized (the macro above does this).
-struct SkPODSpinlock {
+class SkPODSpinlock {
+public:
void acquire() {
- // To act as a mutex, we need an acquire barrier.
- while(sk_atomic_exchange(&fLocked, true, sk_memory_order_acquire)) { /*spin*/ }
+ // To act as a mutex, we need an acquire barrier if we take the lock.
+ if (sk_atomic_exchange(&fLocked, true, sk_memory_order_acquire)) {
+ // Lock was contended. Fall back to an out-of-line spin loop.
+ this->contendedAcquire();
+ }
}
+
void release() {
// To act as a mutex, we need a release barrier.
sk_atomic_store(&fLocked, false, sk_memory_order_release);
}
+private:
+ void contendedAcquire();
bool fLocked;
};