Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: include/core/SkSpinlock.h

Issue 1039323002: Extract the spinlock from SkOnce as SkSpinlock. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: quotes Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 // This file is not part of the public Skia API.
9
10 #ifndef SkSpinlock_DEFINED
11 #define SkSpinlock_DEFINED
12
13 #include "SkAtomics.h"
14
15 #define SK_DECLARE_STATIC_SPINLOCK(name) namespace {} static SkPODSpinlock name
16
17 // This class has no constructor and must be zero-initialized (the macro above d oes this).
18 struct SkPODSpinlock {
19 void acquire() {
20 // To act as a mutex, we need an acquire barrier.
21 while(sk_atomic_exchange(&fLocked, true, sk_memory_order_acquire)) { /*s pin*/ }
22 }
23 void release() {
24 // To act as a mutex, we need a release barrier.
25 sk_atomic_store(&fLocked, false, sk_memory_order_release);
26 }
27
28 bool fLocked;
29 };
30
31 // For non-global-static use cases, this is normally what you want.
32 class SkSpinlock : public SkPODSpinlock {
33 public:
34 SkSpinlock() { this->release(); }
35 };
36
37 #endif//SkSpinlock_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698