Flutter Engine
The Flutter Engine
SkMutex.h
Go to the documentation of this file.
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
16
17class SK_CAPABILITY("mutex") SkMutex {
18public:
19 constexpr SkMutex() = default;
20
21 ~SkMutex() {
22 this->assertNotHeld();
23 }
24
25 void acquire() SK_ACQUIRE() {
26 fSemaphore.wait();
27 SkDEBUGCODE(fOwner = SkGetThreadID();)
28 }
29
30 void release() SK_RELEASE_CAPABILITY() {
31 this->assertHeld();
33 fSemaphore.signal();
34 }
35
36 void assertHeld() SK_ASSERT_CAPABILITY(this) {
37 SkASSERT(fOwner == SkGetThreadID());
38 }
39
40 void assertNotHeld() {
41 SkASSERT(fOwner == kIllegalThreadID);
42 }
43
44private:
45 SkSemaphore fSemaphore{1};
47};
48
50public:
51 SkAutoMutexExclusive(SkMutex& mutex) SK_ACQUIRE(mutex) : fMutex(mutex) { fMutex.acquire(); }
53
56
59
60private:
61 SkMutex& fMutex;
62};
63
64#endif // SkMutex_DEFINED
#define SkASSERT(cond)
Definition: SkAssert.h:116
class SK_CAPABILITY("mutex") SkMutex
Definition: SkMutex.h:17
#define SK_SCOPED_CAPABILITY
#define SK_RELEASE_CAPABILITY(...)
#define SK_ACQUIRE(...)
#define SK_ASSERT_CAPABILITY(x)
SkThreadID SkGetThreadID()
Definition: SkThreadID.cpp:15
const SkThreadID kIllegalThreadID
Definition: SkThreadID.h:21
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
int64_t SkThreadID
Definition: SkThreadID.h:16
~SkAutoMutexExclusive() SK_RELEASE_CAPABILITY()
Definition: SkMutex.h:52
SkAutoMutexExclusive(SkAutoMutexExclusive &&)=delete
SkAutoMutexExclusive & operator=(SkAutoMutexExclusive &&)=delete
SkAutoMutexExclusive(const SkAutoMutexExclusive &)=delete
SkAutoMutexExclusive & operator=(const SkAutoMutexExclusive &)=delete
SkAutoMutexExclusive(SkMutex &mutex) SK_ACQUIRE(mutex)
Definition: SkMutex.h:51