CTRE Phoenix 6 C++ 24.3.0
RcManualEvent.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
10#include <condition_variable>
11
12namespace ctre {
13namespace phoenix {
14namespace threading {
15 /**
16 * Reference-counted Manual Event. Each Signal()
17 * increments a reference count, and each Clear()
18 * decrements the count. The event is signaled while
19 * the count is greater than 0.
20 *
21 * This is useful for a situation where multiple threads
22 * signal an operation to run, and the operation should not
23 * stop until all threads clear the event.
24 */
26 private:
27 size_t _signal = 0;
28 mutable size_t _waitCnt = 0;
29 mutable std::mutex _m;
30 mutable std::condition_variable _cv;
31
32 public:
33 /**
34 * Wait for event to be signaled, or for timeout
35 * \returns true if event is signaled, false if timed out.
36 */
37 bool WaitForSignal(int timeoutMs) const;
38
39 /**
40 * Signal the event. Any threads waiting on WaitForSignal() will return true.
41 * The caller must clear the signal once it is done, otherwise the reference
42 * count may never return to 0.
43 */
44 void Signal();
45 /**
46 * Clear the event. Any threads waiting on WaitForSignal() will time out
47 * if this is the last thread to clear the signal.
48 */
49 void Clear();
50 /**
51 * Reset the event signal to 0 without signaling other threads.
52 */
53 void Reset();
54 };
55}
56}
57}
Reference-counted Manual Event.
Definition: RcManualEvent.hpp:25
bool WaitForSignal(int timeoutMs) const
Wait for event to be signaled, or for timeout.
void Reset()
Reset the event signal to 0 without signaling other threads.
#define CTREXPORT
Definition: export.h:14
Definition: string_util.hpp:15