/src/skia/include/private/base/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/private/base/SkAssert.h" |
12 | | #include "include/private/base/SkDebug.h" |
13 | | #include "include/private/base/SkSemaphore.h" |
14 | | #include "include/private/base/SkThreadAnnotations.h" |
15 | | #include "include/private/base/SkThreadID.h" |
16 | | |
17 | | class SK_CAPABILITY("mutex") SkMutex { |
18 | | public: |
19 | 85.8M | constexpr SkMutex() = default; |
20 | | |
21 | 85.8M | ~SkMutex() { |
22 | 85.8M | this->assertNotHeld(); |
23 | 85.8M | } |
24 | | |
25 | 832M | void acquire() SK_ACQUIRE() { |
26 | 832M | fSemaphore.wait(); |
27 | 832M | SkDEBUGCODE(fOwner = SkGetThreadID();) |
28 | 832M | } Line | Count | Source | 25 | 416M | void acquire() SK_ACQUIRE() { | 26 | 416M | fSemaphore.wait(); | 27 | 416M | SkDEBUGCODE(fOwner = SkGetThreadID();) | 28 | 416M | } |
Line | Count | Source | 25 | 416M | void acquire() SK_ACQUIRE() { | 26 | 416M | fSemaphore.wait(); | 27 | 416M | SkDEBUGCODE(fOwner = SkGetThreadID();) | 28 | 416M | } |
|
29 | | |
30 | 832M | void release() SK_RELEASE_CAPABILITY() { |
31 | 832M | this->assertHeld(); |
32 | 832M | SkDEBUGCODE(fOwner = kIllegalThreadID;) |
33 | 832M | fSemaphore.signal(); |
34 | 832M | } Line | Count | Source | 30 | 416M | void release() SK_RELEASE_CAPABILITY() { | 31 | 416M | this->assertHeld(); | 32 | 416M | SkDEBUGCODE(fOwner = kIllegalThreadID;) | 33 | 416M | fSemaphore.signal(); | 34 | 416M | } |
Line | Count | Source | 30 | 416M | void release() SK_RELEASE_CAPABILITY() { | 31 | 416M | this->assertHeld(); | 32 | 416M | SkDEBUGCODE(fOwner = kIllegalThreadID;) | 33 | 416M | fSemaphore.signal(); | 34 | 416M | } |
|
35 | | |
36 | 416M | void assertHeld() SK_ASSERT_CAPABILITY(this) { |
37 | 416M | SkASSERT(fOwner == SkGetThreadID()); |
38 | 416M | } |
39 | | |
40 | 85.8M | void assertNotHeld() { |
41 | 85.8M | SkASSERT(fOwner == kIllegalThreadID); |
42 | 85.8M | } |
43 | | |
44 | | private: |
45 | | SkSemaphore fSemaphore{1}; |
46 | | SkDEBUGCODE(SkThreadID fOwner{kIllegalThreadID};) |
47 | | }; |
48 | | |
49 | | class SK_SCOPED_CAPABILITY SkAutoMutexExclusive { |
50 | | public: |
51 | 416M | SkAutoMutexExclusive(SkMutex& mutex) SK_ACQUIRE(mutex) : fMutex(mutex) { fMutex.acquire(); } |
52 | 416M | ~SkAutoMutexExclusive() SK_RELEASE_CAPABILITY() { fMutex.release(); } |
53 | | |
54 | | SkAutoMutexExclusive(const SkAutoMutexExclusive&) = delete; |
55 | | SkAutoMutexExclusive(SkAutoMutexExclusive&&) = delete; |
56 | | |
57 | | SkAutoMutexExclusive& operator=(const SkAutoMutexExclusive&) = delete; |
58 | | SkAutoMutexExclusive& operator=(SkAutoMutexExclusive&&) = delete; |
59 | | |
60 | | private: |
61 | | SkMutex& fMutex; |
62 | | }; |
63 | | |
64 | | #endif // SkMutex_DEFINED |