/src/skia/include/private/SkMutex.h
Line | Count | Source |
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 | | #ifndef SkMutex_DEFINED |
9 | | #define SkMutex_DEFINED |
10 | | |
11 | | #include "include/core/SkTypes.h" |
12 | | #include "include/private/SkMacros.h" |
13 | | #include "include/private/SkSemaphore.h" |
14 | | #include "include/private/SkThreadAnnotations.h" |
15 | | #include "include/private/SkThreadID.h" |
16 | | |
17 | | class SK_CAPABILITY("mutex") SkMutex { |
18 | | public: |
19 | 6.85M | constexpr SkMutex() = default; |
20 | | |
21 | 4.59G | void acquire() SK_ACQUIRE() { |
22 | 4.59G | fSemaphore.wait(); |
23 | 2.29G | SkDEBUGCODE(fOwner = SkGetThreadID();) |
24 | 4.59G | } Line | Count | Source | 21 | 2.29G | void acquire() SK_ACQUIRE() { | 22 | 2.29G | fSemaphore.wait(); | 23 | 2.29G | SkDEBUGCODE(fOwner = SkGetThreadID();) | 24 | 2.29G | } |
Line | Count | Source | 21 | 2.29G | void acquire() SK_ACQUIRE() { | 22 | 2.29G | fSemaphore.wait(); | 23 | 2.29G | SkDEBUGCODE(fOwner = SkGetThreadID();) | 24 | 2.29G | } |
|
25 | | |
26 | 4.59G | void release() SK_RELEASE_CAPABILITY() { |
27 | 4.59G | this->assertHeld(); |
28 | 2.29G | SkDEBUGCODE(fOwner = kIllegalThreadID;) |
29 | 4.59G | fSemaphore.signal(); |
30 | 4.59G | } Line | Count | Source | 26 | 2.29G | void release() SK_RELEASE_CAPABILITY() { | 27 | 2.29G | this->assertHeld(); | 28 | 2.29G | SkDEBUGCODE(fOwner = kIllegalThreadID;) | 29 | 2.29G | fSemaphore.signal(); | 30 | 2.29G | } |
Line | Count | Source | 26 | 2.29G | void release() SK_RELEASE_CAPABILITY() { | 27 | 2.29G | this->assertHeld(); | 28 | 2.29G | SkDEBUGCODE(fOwner = kIllegalThreadID;) | 29 | 2.29G | fSemaphore.signal(); | 30 | 2.29G | } |
|
31 | | |
32 | 2.31G | void assertHeld() SK_ASSERT_CAPABILITY(this) { |
33 | 2.31G | SkASSERT(fOwner == SkGetThreadID()); |
34 | 2.31G | } Line | Count | Source | 32 | 2.31G | void assertHeld() SK_ASSERT_CAPABILITY(this) { | 33 | 2.31G | SkASSERT(fOwner == SkGetThreadID()); | 34 | 2.31G | } |
Line | Count | Source | 32 | 21.5k | void assertHeld() SK_ASSERT_CAPABILITY(this) { | 33 | 21.5k | SkASSERT(fOwner == SkGetThreadID()); | 34 | 21.5k | } |
|
35 | | |
36 | | private: |
37 | | SkSemaphore fSemaphore{1}; |
38 | | SkDEBUGCODE(SkThreadID fOwner{kIllegalThreadID};) |
39 | | }; |
40 | | |
41 | | class SK_SCOPED_CAPABILITY SkAutoMutexExclusive { |
42 | | public: |
43 | 2.27G | SkAutoMutexExclusive(SkMutex& mutex) SK_ACQUIRE(mutex) : fMutex(mutex) { fMutex.acquire(); } |
44 | 2.27G | ~SkAutoMutexExclusive() SK_RELEASE_CAPABILITY() { fMutex.release(); } |
45 | | |
46 | | SkAutoMutexExclusive(const SkAutoMutexExclusive&) = delete; |
47 | | SkAutoMutexExclusive(SkAutoMutexExclusive&&) = delete; |
48 | | |
49 | | SkAutoMutexExclusive& operator=(const SkAutoMutexExclusive&) = delete; |
50 | | SkAutoMutexExclusive& operator=(SkAutoMutexExclusive&&) = delete; |
51 | | |
52 | | private: |
53 | | SkMutex& fMutex; |
54 | | }; |
55 | | |
56 | | #endif // SkMutex_DEFINED |