-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequence_checker_internal.h
79 lines (63 loc) · 2.16 KB
/
sequence_checker_internal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* sequence_checker_internal.h
* Copyright (C) 2023 youfa <[email protected]>
*
* Distributed under terms of the GPLv2 license.
*/
#ifndef SEQUENCE_CHECKER_IMPL_H
#define SEQUENCE_CHECKER_IMPL_H
#include <string>
#include "base/mutex.h"
#include "base/task_util/task_runner_base.h"
#include "base/thread_annotation.h"
namespace ave {
namespace base {
namespace ave_sequence_checker_internal {
class SequenceCheckerImpl {
public:
SequenceCheckerImpl();
~SequenceCheckerImpl() = default;
bool IsCurrent() const;
void Detach();
std::string ExpectationToString() const;
private:
mutable Mutex lock_;
// These are mutable so that IsCurrent can set them.
mutable bool attached_ GUARDED_BY(lock_);
mutable pthread_t valid_thread_ GUARDED_BY(lock_);
mutable const base::TaskRunnerBase* valid_runner_ GUARDED_BY(lock_);
mutable const void* valid_system_runner_ GUARDED_BY(lock_);
};
// Do nothing implementation, for use in release mode.
//
// Note: You should almost always use the SequenceChecker class to get the
// right version for your build configuration.
class SequenceCheckerDoNothing {
public:
bool IsCurrent() const { return true; }
void Detach() {}
};
// Helper class used by AVE_DCHECK_RUN_ON (see example usage below).
class SCOPED_CAPABILITY SequenceCheckerScope {
public:
template <typename ThreadLikeObject>
explicit SequenceCheckerScope(const ThreadLikeObject* thread_like_object)
ACQUIRE(thread_like_object) {}
SequenceCheckerScope(const SequenceCheckerScope&) = delete;
SequenceCheckerScope& operator=(const SequenceCheckerScope&) = delete;
~SequenceCheckerScope() RELEASE() {}
template <typename ThreadLikeObject>
static bool IsCurrent(const ThreadLikeObject* thread_like_object) {
return thread_like_object->IsCurrent();
}
};
std::string ExpectationToString(const SequenceCheckerImpl* checker);
// Catch-all implementation for types other than explicitly supported above.
template <typename ThreadLikeObject>
std::string ExpectationToString(const ThreadLikeObject*) {
return std::string();
}
} // namespace ave_sequence_checker_internal
} // namespace base
} // namespace ave
#endif /* !SEQUENCE_CHECKER_IMPL_H */