15 #ifndef SHAKA_EMBEDDED_DEBUG_THREAD_EVENT_H_ 16 #define SHAKA_EMBEDDED_DEBUG_THREAD_EVENT_H_ 18 #include <glog/logging.h> 50 provider_.store(thread, std::memory_order_release);
51 #ifdef DEBUG_DEADLOCKS 52 WaitingTracker::UpdateProvider(
this);
57 const std::string name_;
58 std::atomic<Thread*> provider_;
77 std::shared_future<T> future;
79 std::unique_lock<std::mutex> lock(mutex_);
83 #ifdef DEBUG_DEADLOCKS 84 auto scope = WaitingTracker::ThreadWaiting(
this);
94 std::unique_lock<std::mutex> lock(mutex_);
105 template <
typename _Mutex>
107 DCHECK(lock.owns_lock());
109 std::shared_future<T> future;
111 std::unique_lock<std::mutex> lock(mutex_);
117 #ifdef DEBUG_DEADLOCKS 118 auto scope = WaitingTracker::ThreadWaiting(
this);
129 CHECK(SignalAllIfNotSet());
131 template <
typename U>
133 CHECK(SignalAllIfNotSet(std::forward<U>(value)));
146 std::promise<void> p;
148 std::unique_lock<std::mutex> lock(mutex_);
152 p = std::move(promise_);
157 template <
typename U>
161 std::unique_lock<std::mutex> lock(mutex_);
165 p = std::move(promise_);
167 p.set_value(std::forward<U>(value));
181 std::unique_lock<std::mutex> lock(mutex_);
186 void ResetInternal() {
187 #ifdef DEBUG_DEADLOCKS 189 WaitingTracker::RemoveWaitable(
this);
198 promise_.set_exception(std::exception_ptr());
201 promise_ = std::promise<T>();
202 future_ = promise_.get_future().share();
206 std::promise<T> promise_;
207 std::shared_future<T> future_;
208 bool is_set_ =
false;
213 #endif // SHAKA_EMBEDDED_DEBUG_THREAD_EVENT_H_ ~ThreadEventBase() override
std::shared_future< T > future()
ThreadEvent(const std::string &name)
void SignalAll(U &&value)
ThreadEventBase(const std::string &name)
T ResetAndWaitWhileUnlocked(std::unique_lock< _Mutex > &lock)
bool SignalAllIfNotSet(U &&value)
void SetProvider(Thread *thread)
std::thread::id GetProvider() const override