17 #ifndef CARTOGRAPHER_COMMON_MUTEX_H_ 18 #define CARTOGRAPHER_COMMON_MUTEX_H_ 20 #include <condition_variable> 30 #if defined(__SUPPORT_TS_ANNOTATION__) || defined(__clang__) 31 #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x)) 33 #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op 36 #define CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(capability(x)) 38 #define SCOPED_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable) 40 #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) 42 #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x)) 44 #define REQUIRES(...) \ 45 THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__)) 47 #define ACQUIRE(...) \ 48 THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__)) 50 #define RELEASE(...) \ 51 THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__)) 53 #define EXCLUDES(...) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__)) 55 #define NO_THREAD_SAFETY_ANALYSIS \ 56 THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) 67 Locker(Mutex* mutex)
ACQUIRE(mutex) : mutex_(mutex), lock_(mutex->mutex_) {}
71 mutex_->condition_.notify_all();
74 template <
typename Predicate>
75 void Await(Predicate predicate)
REQUIRES(
this) {
76 mutex_->condition_.wait(lock_, predicate);
79 template <
typename Predicate>
82 return mutex_->condition_.wait_for(lock_, timeout, predicate);
87 std::unique_lock<std::mutex> lock_;
91 std::condition_variable condition_;
100 #endif // CARTOGRAPHER_COMMON_MUTEX_H_ #define SCOPED_CAPABILITY
UniversalTimeScaleClock::duration Duration
class CAPABILITY("mutex") Mutex
Mutex::Locker MutexLocker