WPILibC++ 2024.3.2
EventVector.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include "wpi/SmallVector.h"
9#include "wpi/mutex.h"
10
11namespace wpi {
15
16 /**
17 * Adds an event to the event vector.
18 *
19 * @param handle the event to add
20 */
21 void Add(WPI_EventHandle handle) {
22 std::scoped_lock lock{mutex};
23 events.emplace_back(handle);
24 }
25
26 /**
27 * Removes an event from the event vector.
28 *
29 * @param handle The event to remove
30 */
31 void Remove(WPI_EventHandle handle) {
32 std::scoped_lock lock{mutex};
33 auto it = std::find_if(
35 [=](const WPI_EventHandle fromHandle) { return fromHandle == handle; });
36 if (it != events.end()) {
37 events.erase(it);
38 }
39 }
40
41 /**
42 * Wakes up all events in the event vector.
43 */
44 void Wakeup() {
45 std::scoped_lock lock{mutex};
46 for (auto&& handle : events) {
47 wpi::SetEvent(handle);
48 }
49 }
50};
51} // namespace wpi
This file defines the SmallVector class.
WPI_Handle WPI_EventHandle
An event handle.
Definition: Synchronization.h:25
iterator erase(const_iterator CI)
Definition: SmallVector.h:743
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:943
iterator begin()
Definition: SmallVector.h:272
iterator end()
Definition: SmallVector.h:274
Definition: ntcore_cpp.h:26
void SetEvent(WPI_EventHandle handle)
Sets an event to signaled state.
Definition: EventVector.h:12
void Wakeup()
Wakes up all events in the event vector.
Definition: EventVector.h:44
wpi::mutex mutex
Definition: EventVector.h:13
wpi::SmallVector< WPI_EventHandle, 4 > events
Definition: EventVector.h:14
void Add(WPI_EventHandle handle)
Adds an event to the event vector.
Definition: EventVector.h:21
void Remove(WPI_EventHandle handle)
Removes an event from the event vector.
Definition: EventVector.h:31
::std::mutex mutex
Definition: mutex.h:17