class sequence_checker
Defined at line 42 of file ../../sdk/lib/async/include/lib/async/cpp/sequence_checker.h
A simple class that records the identity of the sequence that it was created
on, and at later points can tell if the current sequence is the same as its
creation sequence. This class is thread-safe.
In addition to providing an explicit check of the current sequence,
|sequence_checker| complies with BasicLockable, checking the current sequence
when |lock| is called. This allows static thread safety analysis to be used
to ensure that resources are accessed in a context that is checked (at debug
runtime) to ensure that it's running on the correct sequence:
class MyClass {
public:
MyClass(async_dispatcher_t* dispatcher) : sequence_checker_(dispatcher) {}
void Foo() {
std::lock_guard
<sequence
::sequence_checker> locker(sequence_checker_);
resource_ = 0;
}
private:
sequence::sequence_checker sequence_checker_;
int resource_ __TA_GUARDED(sequence_checker_);
};
This class is useful for code that works exclusively with asynchronous
runtimes that support sequences.
Public Methods
void sequence_checker (async_dispatcher_t * dispatcher, const char * application_description)
Constructs a sequence checker bound to the currently running sequence.
Panics if the current thread is not associated with a sequence.
If |application_description| is not null, it will be prepended in front of
synchronization check failure panic messages. For example, one may specify
"|Foo| is thread unsafe." so that users understand whose threading
invariants did they violate.
Defined at line 19 of file ../../sdk/lib/async/sequence_checker.cc
std::variant<std::monostate, std::string> is_sequence_valid ()
Returns |monostate| if the current sequence is the sequence this object was
created on and a |string| describing the error otherwise.
Defined at line 32 of file ../../sdk/lib/async/sequence_checker.cc
void lock ()
Implementation of the BaseLockable requirement
Defined at line 41 of file ../../sdk/lib/async/sequence_checker.cc
void ~sequence_checker ()
Defined at line 54 of file ../../sdk/lib/async/include/lib/async/cpp/sequence_checker.h
void unlock ()
Defined at line 63 of file ../../sdk/lib/async/include/lib/async/cpp/sequence_checker.h