CTRE Phoenix 6 C++ 25.0.0-beta-4
Loading...
Searching...
No Matches
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 size_t _refCnt = 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 * \param timeoutMs timeout of the wait; -1 is indefinite, 0 is a fast check
36 * \returns true if event is signaled, false if timed out.
37 */
38 bool WaitForSignal(int timeoutMs) const;
39
40 /**
41 * Signal the event. Any threads waiting on WaitForSignal() will return true.
42 * The caller must clear the signal once it is done, otherwise the reference
43 * count may never return to 0.
44 */
45 void Signal();
46 /**
47 * Clear the event signal without signaling other threads.
48 */
49 void Clear();
50 /**
51 * Reset the event signal to 0 and force any threads waiting on WaitForSignal() to time out.
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 and force any threads waiting on WaitForSignal() to time out.
void Clear()
Clear the event signal without signaling other threads.
#define CTREXPORT
Definition export.h:14
Definition StatusCodes.h:18