RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
EventVector.java
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
5package org.wpilib.util.concurrent;
6
7import java.util.ArrayList;
8import java.util.List;
9import java.util.concurrent.locks.ReentrantLock;
10import org.wpilib.util.WPIUtilJNI;
11
13public class EventVector {
14 private final ReentrantLock m_lock = new ReentrantLock();
15 private final List<Integer> m_events = new ArrayList<>();
16
18 public EventVector() {}
19
25 public void add(int handle) {
26 m_lock.lock();
27 try {
28 m_events.add(handle);
29 } finally {
30 m_lock.unlock();
31 }
32 }
33
39 public void remove(int handle) {
40 m_lock.lock();
41 try {
42 m_events.removeIf(x -> x == handle);
43 } finally {
44 m_lock.unlock();
45 }
46 }
47
49 public void wakeup() {
50 m_lock.lock();
51 try {
52 for (int eventHandle : m_events) {
53 WPIUtilJNI.setEvent(eventHandle);
54 }
55 } finally {
56 m_lock.unlock();
57 }
58 }
59}