13 #ifndef __STOUT_SYNCHRONIZED_HPP__ 14 #define __STOUT_SYNCHRONIZED_HPP__ 17 #include <condition_variable> 19 #include <type_traits> 21 #include <glog/logging.h> 31 : t_(CHECK_NOTNULL(t)), release_(
release)
40 explicit operator bool()
const {
return false; }
56 [](T* t) { t->lock(); },
57 [](T* t) { t->unlock(); }
67 [](std::atomic_flag* lock) {
68 while (lock->test_and_set(std::memory_order_acquire)) {}
70 [](std::atomic_flag* lock) {
71 lock->clear(std::memory_order_release);
80 return *CHECK_NOTNULL(t);
96 #define SYNCHRONIZED_PREFIX CAT(__synchronizer_, __LINE__) 97 #define SYNCHRONIZED_VAR CAT(SYNCHRONIZED_PREFIX, _var__) 98 #define SYNCHRONIZED_LABEL CAT(SYNCHRONIZED_PREFIX, _label__) 139 #define synchronized(m) \ 140 if (Synchronized<typename std::remove_pointer<decltype(m)>::type> \ 141 SYNCHRONIZED_VAR = ::synchronize(::synchronized_get_pointer(&m))) { \ 142 goto SYNCHRONIZED_LABEL; \ 143 } else SYNCHRONIZED_LABEL: 160 template <
typename CV,
typename Lock>
192 CHECK_NOTNULL(mutex);
197 std::unique_lock<std::mutex> lock(*mutex, std::adopt_lock);
221 template <
typename Lock>
224 #endif // __STOUT_SYNCHRONIZED_HPP__ Synchronized< T > synchronize(T *t)
Definition: synchronized.hpp:52
Synchronized(T *t, void(*acquire)(T *), void(*release)(T *))
Definition: synchronized.hpp:30
Definition: synchronized.hpp:27
void synchronized_wait(CV *cv, Lock *lock)
Waits on the condition variable associated with 'lock' which has already been synchronized.
~Synchronized()
Definition: synchronized.hpp:36
Try< Version > release()
Definition: os.hpp:378
T * synchronized_get_pointer(T **t)
Definition: synchronized.hpp:78