10#include <initializer_list>
62 bool initialState =
false);
97 int maximumCount = INT_MAX);
117 int* prevCount =
nullptr);
152 std::span<WPI_Handle> signaled);
166 std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled) {
167 return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled);
185 std::span<WPI_Handle> signaled,
186 double timeout,
bool* timedOut);
202 std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled,
203 double timeout,
bool* timedOut) {
204 return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled,
217 bool initialState =
false);
258 explicit Event(
bool manualReset =
false,
bool initialState =
false)
259 : m_handle{
CreateEvent(manualReset, initialState)} {}
269 Event(
Event&& rhs) : m_handle{rhs.m_handle} { rhs.m_handle = 0; }
274 m_handle = rhs.m_handle;
323 explicit Semaphore(
int initialCount = 0,
int maximumCount = INT_MAX)
339 m_handle = rhs.m_handle;
367 bool Release(
int releaseCount = 1,
int* prevCount =
nullptr) {
392 bool initialState =
false)
412 m_handle = rhs.m_handle;
422 operator T()
const {
return m_handle; }
void WPI_DestroySemaphore(WPI_SemaphoreHandle handle)
Destroys a semaphore.
int WPI_WaitForObjectsTimeout(const WPI_Handle *handles, int handles_count, WPI_Handle *signaled, double timeout, int *timed_out)
Waits for one or more handles to be signaled, with timeout.
WPI_SemaphoreHandle WPI_CreateSemaphore(int initial_count, int maximum_count)
Creates a semaphore.
void WPI_SetSignalObject(WPI_Handle handle)
Sets a handle to signaled state.
int WPI_ReleaseSemaphore(WPI_SemaphoreHandle handle, int release_count, int *prev_count)
Releases N counts of a semaphore.
void WPI_ResetSignalObject(WPI_Handle handle)
Sets a handle to non-signaled state.
WPI_Handle WPI_SemaphoreHandle
A semaphore handle.
Definition: Synchronization.h:28
unsigned int WPI_Handle
Generic handle for all WPI handle-based interfaces.
Definition: Synchronization.h:22
int WPI_WaitForObjectTimeout(WPI_Handle handle, double timeout, int *timed_out)
Waits for an handle to be signaled, with timeout.
WPI_Handle WPI_EventHandle
An event handle.
Definition: Synchronization.h:25
void WPI_CreateSignalObject(WPI_Handle handle, int manual_reset, int initial_state)
Sets up signaling for an arbitrary handle.
void WPI_DestroyEvent(WPI_EventHandle handle)
Destroys an event.
WPI_EventHandle WPI_CreateEvent(int manual_reset, int initial_state)
Creates an event.
void WPI_DestroySignalObject(WPI_Handle handle)
Cleans up signaling for a handle.
void WPI_ResetEvent(WPI_EventHandle handle)
Sets an event to non-signaled state.
int WPI_WaitForObject(WPI_Handle handle)
Waits for an handle to be signaled.
void WPI_SetEvent(WPI_EventHandle handle)
Sets an event to signaled state.
int WPI_WaitForObjects(const WPI_Handle *handles, int handles_count, WPI_Handle *signaled)
Waits for one or more handles to be signaled.
An atomic signaling event for synchronization.
Definition: Synchronization.h:250
void Set()
Sets the event to signaled state.
Definition: Synchronization.h:296
Event(bool manualReset=false, bool initialState=false)
Constructor.
Definition: Synchronization.h:258
Event & operator=(const Event &)=delete
Event & operator=(Event &&rhs)
Definition: Synchronization.h:270
Event(Event &&rhs)
Definition: Synchronization.h:269
~Event()
Definition: Synchronization.h:260
void Reset()
Sets the event to non-signaled state.
Definition: Synchronization.h:301
WPI_EventHandle GetHandle() const
Gets the event handle (e.g.
Definition: Synchronization.h:291
Event(const Event &)=delete
A semaphore for synchronization.
Definition: Synchronization.h:315
~Semaphore()
Definition: Synchronization.h:325
Semaphore & operator=(const Semaphore &)=delete
bool Release(int releaseCount=1, int *prevCount=nullptr)
Releases N counts of the semaphore.
Definition: Synchronization.h:367
Semaphore(int initialCount=0, int maximumCount=INT_MAX)
Constructor.
Definition: Synchronization.h:323
Semaphore & operator=(Semaphore &&rhs)
Definition: Synchronization.h:335
Semaphore(Semaphore &&rhs)
Definition: Synchronization.h:334
WPI_SemaphoreHandle GetHandle() const
Gets the semaphore handle (e.g.
Definition: Synchronization.h:356
Semaphore(const Semaphore &)=delete
RAII wrapper for signaling handles.
Definition: Synchronization.h:382
void Reset()
Sets the handle to non-signaled state.
Definition: Synchronization.h:439
SignalObject(T handle=0, bool manualReset=false, bool initialState=false)
Constructor.
Definition: Synchronization.h:391
SignalObject & operator=(SignalObject &&rhs)
Definition: Synchronization.h:408
SignalObject(const SignalObject &)=delete
T GetHandle() const
Gets the handle (e.g.
Definition: Synchronization.h:429
void Set()
Sets the handle to signaled state.
Definition: Synchronization.h:434
SignalObject(SignalObject &&rhs)
Definition: Synchronization.h:405
~SignalObject()
Definition: Synchronization.h:396
SignalObject & operator=(const SignalObject &)=delete
Definition: ntcore_cpp.h:26
void DestroySemaphore(WPI_SemaphoreHandle handle)
Destroys a semaphore.
void CreateSignalObject(WPI_Handle handle, bool manualReset=false, bool initialState=false)
Sets up signaling for an arbitrary handle.
void SetEvent(WPI_EventHandle handle)
Sets an event to signaled state.
void ResetSignalObject(WPI_Handle handle)
Sets a handle to non-signaled state.
WPI_EventHandle CreateEvent(bool manualReset=false, bool initialState=false)
Creates an event.
void ResetEvent(WPI_EventHandle handle)
Sets an event to non-signaled state.
bool WaitForObject(WPI_Handle handle)
Waits for an handle to be signaled.
void DestroySignalObject(WPI_Handle handle)
Cleans up signaling for a handle.
void SetSignalObject(WPI_Handle handle)
Sets a handle to signaled state.
bool ReleaseSemaphore(WPI_SemaphoreHandle handle, int releaseCount=1, int *prevCount=nullptr)
Releases N counts of a semaphore.
void DestroyEvent(WPI_EventHandle handle)
Destroys an event.
WPI_SemaphoreHandle CreateSemaphore(int initialCount=0, int maximumCount=INT_MAX)
Creates a semaphore.
std::span< WPI_Handle > WaitForObjects(std::span< const WPI_Handle > handles, std::span< WPI_Handle > signaled)
Waits for one or more handles to be signaled.
constexpr int kHandleTypeSemaphore
Definition: Synchronization.h:42
constexpr int kHandleTypeCSBase
Definition: Synchronization.h:43
constexpr int kHandleTypeNTBase
Definition: Synchronization.h:44
constexpr int kHandleTypeEvent
Standard types for handles.
Definition: Synchronization.h:41
constexpr int kHandleTypeUserBase
Definition: Synchronization.h:46
constexpr int kHandleTypeHALBase
Definition: Synchronization.h:45
constexpr unsigned int kInvalidHandle
Constant representing an invalid handle.
Definition: Synchronization.h:35