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

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

Issue 1936653002: Add reminders that these classes have constexpr default constructors. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « include/private/SkOnce.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkSpinlock_DEFINED 8 #ifndef SkSpinlock_DEFINED
9 #define SkSpinlock_DEFINED 9 #define SkSpinlock_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 #include <atomic> 12 #include <atomic>
13 13
14 class SkSpinlock { 14 class SkSpinlock {
15 public: 15 public:
16 constexpr SkSpinlock() = default;
17
16 void acquire() { 18 void acquire() {
17 // To act as a mutex, we need an acquire barrier when we acquire the loc k. 19 // To act as a mutex, we need an acquire barrier when we acquire the loc k.
18 if (fLocked.exchange(true, std::memory_order_acquire)) { 20 if (fLocked.exchange(true, std::memory_order_acquire)) {
19 // Lock was contended. Fall back to an out-of-line spin loop. 21 // Lock was contended. Fall back to an out-of-line spin loop.
20 this->contendedAcquire(); 22 this->contendedAcquire();
21 } 23 }
22 } 24 }
23 25
24 void release() { 26 void release() {
25 // To act as a mutex, we need a release barrier when we release the lock . 27 // To act as a mutex, we need a release barrier when we release the lock .
26 fLocked.store(false, std::memory_order_release); 28 fLocked.store(false, std::memory_order_release);
27 } 29 }
28 30
29 private: 31 private:
30 SK_API void contendedAcquire(); 32 SK_API void contendedAcquire();
31 33
32 std::atomic<bool> fLocked{false}; 34 std::atomic<bool> fLocked{false};
33 }; 35 };
34 36
35 #endif//SkSpinlock_DEFINED 37 #endif//SkSpinlock_DEFINED
OLDNEW
« no previous file with comments | « include/private/SkOnce.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698