10#include <initializer_list>
35constexpr unsigned int kInvalidHandle = 0;
41constexpr int kHandleTypeEvent = 1;
42constexpr int kHandleTypeSemaphore = 2;
43constexpr int kHandleTypeCSBase = 3;
44constexpr int kHandleTypeNTBase = 16;
45constexpr int kHandleTypeHALBase = 48;
46constexpr int kHandleTypeUserBase = 80;
62 bool initialState =
false);
97 int maximumCount = INT_MAX);
117 int* prevCount =
nullptr);
138bool WaitForObject(
WPI_Handle handle,
double timeout,
bool* timedOut);
151std::span<WPI_Handle> WaitForObjects(std::span<const WPI_Handle> handles,
152 std::span<WPI_Handle> signaled);
165inline std::span<WPI_Handle> WaitForObjects(
166 std::initializer_list<WPI_Handle> handles, std::span<WPI_Handle> signaled) {
167 return WaitForObjects(std::span{handles.begin(), handles.size()}, signaled);
184std::span<WPI_Handle> WaitForObjects(std::span<const WPI_Handle> handles,
185 std::span<WPI_Handle> signaled,
186 double timeout,
bool* timedOut);
201inline std::span<WPI_Handle> WaitForObjects(
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,
217void CreateSignalObject(
WPI_Handle handle,
bool manualReset =
false,
218 bool initialState =
false);
259 explicit Event(
bool manualReset =
false,
bool initialState =
false)
260 : m_handle{CreateEvent(manualReset, initialState)} {}
263 DestroyEvent(m_handle);
267 Event(
const Event&) =
delete;
268 Event& operator=(
const Event&) =
delete;
270 Event(Event&& rhs) : m_handle{rhs.m_handle} { rhs.m_handle = 0; }
271 Event& operator=(Event&& rhs) {
273 DestroyEvent(m_handle);
275 m_handle = rhs.m_handle;
285 explicit operator WPI_Handle()
const {
return m_handle; }
297 void Set() { SetEvent(m_handle); }
302 void Reset() { ResetEvent(m_handle); }
316class Semaphore final {
324 explicit Semaphore(
int initialCount = 0,
int maximumCount = INT_MAX)
325 : m_handle{CreateSemaphore(initialCount, maximumCount)} {}
328 DestroySemaphore(m_handle);
332 Semaphore(
const Semaphore&) =
delete;
333 Semaphore& operator=(
const Semaphore&) =
delete;
335 Semaphore(Semaphore&& rhs) : m_handle{rhs.m_handle} { rhs.m_handle = 0; }
336 Semaphore& operator=(Semaphore&& rhs) {
338 DestroySemaphore(m_handle);
340 m_handle = rhs.m_handle;
350 explicit operator WPI_Handle()
const {
return m_handle; }
368 bool Release(
int releaseCount = 1,
int* prevCount =
nullptr) {
369 return ReleaseSemaphore(m_handle, releaseCount, prevCount);
383class SignalObject final {
392 explicit SignalObject(T handle = 0,
bool manualReset =
false,
393 bool initialState =
false)
395 CreateSignalObject(handle, manualReset, initialState);
399 DestroySignalObject(m_handle);
403 SignalObject(
const SignalObject&) =
delete;
404 SignalObject& operator=(
const SignalObject&) =
delete;
406 SignalObject(SignalObject&& rhs) : m_handle{rhs.m_handle} {
409 SignalObject& operator=(SignalObject&& rhs) {
411 DestroySemaphore(m_handle);
413 m_handle = rhs.m_handle;
423 operator T()
const {
return m_handle; }
430 T GetHandle()
const {
return m_handle; }
435 void Set() { SetSignalObject(m_handle); }
440 void Reset() { ResetSignalObject(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.
void Release(NT_Handle pubsubentry)
Stops entry/subscriber/publisher.
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18