Coverage Report

Created: 2024-09-14 07:19

/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
98.5M
    constexpr SkMutex() = default;
20
21
98.5M
    ~SkMutex() {
22
98.5M
        this->assertNotHeld();
23
98.5M
    }
24
25
915M
    void acquire() SK_ACQUIRE() {
26
915M
        fSemaphore.wait();
27
915M
        SkDEBUGCODE(fOwner = SkGetThreadID();)
28
915M
    }
SkMutex::acquire()
Line
Count
Source
25
457M
    void acquire() SK_ACQUIRE() {
26
457M
        fSemaphore.wait();
27
457M
        SkDEBUGCODE(fOwner = SkGetThreadID();)
28
457M
    }
SkMutex::acquire()
Line
Count
Source
25
457M
    void acquire() SK_ACQUIRE() {
26
457M
        fSemaphore.wait();
27
457M
        SkDEBUGCODE(fOwner = SkGetThreadID();)
28
457M
    }
29
30
915M
    void release() SK_RELEASE_CAPABILITY() {
31
915M
        this->assertHeld();
32
915M
        SkDEBUGCODE(fOwner = kIllegalThreadID;)
33
915M
        fSemaphore.signal();
34
915M
    }
SkMutex::release()
Line
Count
Source
30
457M
    void release() SK_RELEASE_CAPABILITY() {
31
457M
        this->assertHeld();
32
457M
        SkDEBUGCODE(fOwner = kIllegalThreadID;)
33
457M
        fSemaphore.signal();
34
457M
    }
SkMutex::release()
Line
Count
Source
30
457M
    void release() SK_RELEASE_CAPABILITY() {
31
457M
        this->assertHeld();
32
457M
        SkDEBUGCODE(fOwner = kIllegalThreadID;)
33
457M
        fSemaphore.signal();
34
457M
    }
35
36
457M
    void assertHeld() SK_ASSERT_CAPABILITY(this) {
37
457M
        SkASSERT(fOwner == SkGetThreadID());
38
457M
    }
39
40
98.5M
    void assertNotHeld() {
41
98.5M
        SkASSERT(fOwner == kIllegalThreadID);
42
98.5M
    }
43
44
private:
45
    SkSemaphore fSemaphore{1};
46
    SkDEBUGCODE(SkThreadID fOwner{kIllegalThreadID};)
47
};
48
49
class SK_SCOPED_CAPABILITY SkAutoMutexExclusive {
50
public:
51
457M
    SkAutoMutexExclusive(SkMutex& mutex) SK_ACQUIRE(mutex) : fMutex(mutex) { fMutex.acquire(); }
52
457M
    ~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