mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiutil] Rename CreateEvent and CreateSemaphore to Make (#8710)
CreateEvent and CreateSemaphore are macros in Windows.h, which causes a ton of trouble. Just rename the functions. Closes #7303 Replaces #7336
This commit is contained in:
@@ -228,8 +228,8 @@ NT_UnsubscribeMultiple
|
||||
NT_WaitForListenerQueue
|
||||
WPI_AllocateString
|
||||
WPI_AllocateStringArray
|
||||
WPI_CreateEvent
|
||||
WPI_CreateSemaphore
|
||||
WPI_MakeEvent
|
||||
WPI_MakeSemaphore
|
||||
WPI_CreateSignalObject
|
||||
WPI_DataLog_AppendBoolean
|
||||
WPI_DataLog_AppendBooleanArray
|
||||
|
||||
@@ -88,7 +88,7 @@ int main(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
WPI_EventHandle eventHandle = WPI_CreateEvent(0, 0);
|
||||
WPI_EventHandle eventHandle = WPI_MakeEvent(0, 0);
|
||||
HAL_ProvideNewDataEventHandle(eventHandle);
|
||||
|
||||
while (1) {
|
||||
|
||||
@@ -595,7 +595,7 @@ public abstract class OpModeRobot extends RobotBase {
|
||||
public final void startCompetition() {
|
||||
System.out.println("********** Robot program startup complete **********");
|
||||
|
||||
int event = WPIUtilJNI.createEvent(false, false);
|
||||
int event = WPIUtilJNI.makeEvent(false, false);
|
||||
DriverStationJNI.provideNewDataEventHandle(event);
|
||||
|
||||
m_notifier = NotifierJNI.createNotifier();
|
||||
@@ -690,7 +690,7 @@ public abstract class OpModeRobot extends RobotBase {
|
||||
|
||||
if (m_word.isEnabled()) {
|
||||
// When enabled, call the opmode run function, then close and clear
|
||||
int endMonitor = WPIUtilJNI.createEvent(true, false);
|
||||
int endMonitor = WPIUtilJNI.makeEvent(true, false);
|
||||
Thread curThread = Thread.currentThread();
|
||||
Thread monitor =
|
||||
new Thread(
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class MotorSafety {
|
||||
|
||||
@SuppressWarnings("PMD.AssignmentInOperand")
|
||||
private static void threadMain() {
|
||||
int event = WPIUtilJNI.createEvent(false, false);
|
||||
int event = WPIUtilJNI.makeEvent(false, false);
|
||||
DriverStationJNI.provideNewDataEventHandle(event);
|
||||
ControlWord controlWord = new ControlWord();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.wpilib.util.WPIUtilJNI;
|
||||
public class DriverStationModeThread implements AutoCloseable {
|
||||
private final AtomicBoolean m_keepAlive = new AtomicBoolean(true);
|
||||
private final AtomicLong m_userControlWord;
|
||||
private final int m_handle = WPIUtilJNI.createEvent(false, false);
|
||||
private final int m_handle = WPIUtilJNI.makeEvent(false, false);
|
||||
private final Thread m_thread;
|
||||
|
||||
/**
|
||||
|
||||
@@ -311,7 +311,7 @@ public final class DriverStationSim {
|
||||
|
||||
/** Updates DriverStation data so that new values are visible to the user program. */
|
||||
public static void notifyNewData() {
|
||||
int handle = WPIUtilJNI.createEvent(false, false);
|
||||
int handle = WPIUtilJNI.makeEvent(false, false);
|
||||
DriverStationJNI.provideNewDataEventHandle(handle);
|
||||
DriverStationDataJNI.notifyNewData();
|
||||
try {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class EducationalRobot extends RobotBase {
|
||||
final ControlWord word = new ControlWord();
|
||||
DriverStationModeThread modeThread = new DriverStationModeThread(word);
|
||||
|
||||
int event = WPIUtilJNI.createEvent(false, false);
|
||||
int event = WPIUtilJNI.makeEvent(false, false);
|
||||
|
||||
DriverStation.provideRefreshedDataEventHandle(event);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Robot extends RobotBase {
|
||||
final ControlWord word = new ControlWord();
|
||||
DriverStationModeThread modeThread = new DriverStationModeThread(word);
|
||||
|
||||
int event = WPIUtilJNI.createEvent(false, false);
|
||||
int event = WPIUtilJNI.makeEvent(false, false);
|
||||
|
||||
DriverStation.provideRefreshedDataEventHandle(event);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class EducationalRobot extends RobotBase {
|
||||
final ControlWord word = new ControlWord();
|
||||
DriverStationModeThread modeThread = new DriverStationModeThread(word);
|
||||
|
||||
int event = WPIUtilJNI.createEvent(false, false);
|
||||
int event = WPIUtilJNI.makeEvent(false, false);
|
||||
|
||||
DriverStation.provideRefreshedDataEventHandle(event);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class EducationalRobot extends RobotBase {
|
||||
final ControlWord word = new ControlWord();
|
||||
DriverStationModeThread modeThread = new DriverStationModeThread(word);
|
||||
|
||||
int event = WPIUtilJNI.createEvent(false, false);
|
||||
int event = WPIUtilJNI.makeEvent(false, false);
|
||||
|
||||
DriverStation.provideRefreshedDataEventHandle(event);
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public class WPIUtilJNI {
|
||||
* @param initialState true to make the event initially in signaled state
|
||||
* @return Event handle
|
||||
*/
|
||||
public static native int createEvent(boolean manualReset, boolean initialState);
|
||||
public static native int makeEvent(boolean manualReset, boolean initialState);
|
||||
|
||||
/**
|
||||
* Destroys an event. Destruction wakes up any waiters.
|
||||
@@ -145,7 +145,7 @@ public class WPIUtilJNI {
|
||||
* @param maximumCount maximum value for the semaphore's internal counter
|
||||
* @return Semaphore handle
|
||||
*/
|
||||
public static native int createSemaphore(int initialCount, int maximumCount);
|
||||
public static native int makeSemaphore(int initialCount, int maximumCount);
|
||||
|
||||
/**
|
||||
* Destroys a semaphore. Destruction wakes up any waiters.
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class Event implements AutoCloseable {
|
||||
* @param initialState true to make the event initially in signaled state
|
||||
*/
|
||||
public Event(boolean manualReset, boolean initialState) {
|
||||
m_handle = WPIUtilJNI.createEvent(manualReset, initialState);
|
||||
m_handle = WPIUtilJNI.makeEvent(manualReset, initialState);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ public final class Semaphore implements AutoCloseable {
|
||||
* @param maximumCount maximum value for the semaphore's internal counter
|
||||
*/
|
||||
public Semaphore(int initialCount, int maximumCount) {
|
||||
m_handle = WPIUtilJNI.createSemaphore(initialCount, maximumCount);
|
||||
m_handle = WPIUtilJNI.makeSemaphore(initialCount, maximumCount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -97,7 +97,7 @@ class ManagerGuard {
|
||||
|
||||
} // namespace
|
||||
|
||||
WPI_EventHandle wpi::util::CreateEvent(bool manualReset, bool initialState) {
|
||||
WPI_EventHandle wpi::util::MakeEvent(bool manualReset, bool initialState) {
|
||||
ManagerGuard guard;
|
||||
if (!guard) {
|
||||
return {};
|
||||
@@ -147,8 +147,8 @@ void wpi::util::ResetEvent(WPI_EventHandle handle) {
|
||||
ResetSignalObject(handle);
|
||||
}
|
||||
|
||||
WPI_SemaphoreHandle wpi::util::CreateSemaphore(int initialCount,
|
||||
int maximumCount) {
|
||||
WPI_SemaphoreHandle wpi::util::MakeSemaphore(int initialCount,
|
||||
int maximumCount) {
|
||||
ManagerGuard guard;
|
||||
if (!guard) {
|
||||
return {};
|
||||
@@ -406,8 +406,8 @@ void wpi::util::DestroySignalObject(WPI_Handle handle) {
|
||||
|
||||
extern "C" {
|
||||
|
||||
WPI_EventHandle WPI_CreateEvent(int manual_reset, int initial_state) {
|
||||
return wpi::util::CreateEvent(manual_reset != 0, initial_state != 0);
|
||||
WPI_EventHandle WPI_MakeEvent(int manual_reset, int initial_state) {
|
||||
return wpi::util::MakeEvent(manual_reset != 0, initial_state != 0);
|
||||
}
|
||||
|
||||
void WPI_DestroyEvent(WPI_EventHandle handle) {
|
||||
@@ -422,8 +422,8 @@ void WPI_ResetEvent(WPI_EventHandle handle) {
|
||||
wpi::util::ResetEvent(handle);
|
||||
}
|
||||
|
||||
WPI_SemaphoreHandle WPI_CreateSemaphore(int initial_count, int maximum_count) {
|
||||
return wpi::util::CreateSemaphore(initial_count, maximum_count);
|
||||
WPI_SemaphoreHandle WPI_MakeSemaphore(int initial_count, int maximum_count) {
|
||||
return wpi::util::MakeSemaphore(initial_count, maximum_count);
|
||||
}
|
||||
|
||||
void WPI_DestroySemaphore(WPI_SemaphoreHandle handle) {
|
||||
|
||||
@@ -194,14 +194,14 @@ Java_org_wpilib_util_WPIUtilJNI_getSystemTime
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_util_WPIUtilJNI
|
||||
* Method: createEvent
|
||||
* Method: makeEvent
|
||||
* Signature: (ZZ)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_wpilib_util_WPIUtilJNI_createEvent
|
||||
Java_org_wpilib_util_WPIUtilJNI_makeEvent
|
||||
(JNIEnv*, jclass, jboolean manualReset, jboolean initialState)
|
||||
{
|
||||
return wpi::util::CreateEvent(manualReset, initialState);
|
||||
return wpi::util::MakeEvent(manualReset, initialState);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -242,14 +242,14 @@ Java_org_wpilib_util_WPIUtilJNI_resetEvent
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_util_WPIUtilJNI
|
||||
* Method: createSemaphore
|
||||
* Method: makeSemaphore
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_wpilib_util_WPIUtilJNI_createSemaphore
|
||||
Java_org_wpilib_util_WPIUtilJNI_makeSemaphore
|
||||
(JNIEnv*, jclass, jint initialCount, jint maximumCount)
|
||||
{
|
||||
return wpi::util::CreateSemaphore(initialCount, maximumCount);
|
||||
return wpi::util::MakeSemaphore(initialCount, maximumCount);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -36,7 +36,7 @@ extern "C" {
|
||||
* @param initial_state true to make the event initially in signaled state
|
||||
* @return Event handle
|
||||
*/
|
||||
WPI_EventHandle WPI_CreateEvent(int manual_reset, int initial_state);
|
||||
WPI_EventHandle WPI_MakeEvent(int manual_reset, int initial_state);
|
||||
|
||||
/**
|
||||
* Destroys an event. Destruction wakes up any waiters.
|
||||
@@ -70,7 +70,7 @@ void WPI_ResetEvent(WPI_EventHandle handle);
|
||||
* @param maximum_count maximum value for the semaphore's internal counter
|
||||
* @return Semaphore handle
|
||||
*/
|
||||
WPI_SemaphoreHandle WPI_CreateSemaphore(int initial_count, int maximum_count);
|
||||
WPI_SemaphoreHandle WPI_MakeSemaphore(int initial_count, int maximum_count);
|
||||
|
||||
/**
|
||||
* Destroys a semaphore. Destruction wakes up any waiters.
|
||||
|
||||
@@ -39,8 +39,7 @@ constexpr int HANDLE_TYPE_USER_BASE = 80;
|
||||
* @param initialState true to make the event initially in signaled state
|
||||
* @return Event handle
|
||||
*/
|
||||
WPI_EventHandle CreateEvent(bool manualReset = false,
|
||||
bool initialState = false);
|
||||
WPI_EventHandle MakeEvent(bool manualReset = false, bool initialState = false);
|
||||
|
||||
/**
|
||||
* Destroys an event. Destruction wakes up any waiters.
|
||||
@@ -74,8 +73,8 @@ void ResetEvent(WPI_EventHandle handle);
|
||||
* @param maximumCount maximum value for the semaphore's internal counter
|
||||
* @return Semaphore handle
|
||||
*/
|
||||
WPI_SemaphoreHandle CreateSemaphore(int initialCount = 0,
|
||||
int maximumCount = INT_MAX);
|
||||
WPI_SemaphoreHandle MakeSemaphore(int initialCount = 0,
|
||||
int maximumCount = INT_MAX);
|
||||
|
||||
/**
|
||||
* Destroys a semaphore. Destruction wakes up any waiters.
|
||||
@@ -237,7 +236,7 @@ class Event final {
|
||||
* @param initialState true to make the event initially in signaled state
|
||||
*/
|
||||
explicit Event(bool manualReset = false, bool initialState = false)
|
||||
: m_handle{CreateEvent(manualReset, initialState)} {}
|
||||
: m_handle{MakeEvent(manualReset, initialState)} {}
|
||||
~Event() {
|
||||
if (m_handle != 0) {
|
||||
DestroyEvent(m_handle);
|
||||
@@ -302,7 +301,7 @@ class Semaphore final {
|
||||
* @param maximumCount maximum value for the semaphore's internal counter
|
||||
*/
|
||||
explicit Semaphore(int initialCount = 0, int maximumCount = INT_MAX)
|
||||
: m_handle{CreateSemaphore(initialCount, maximumCount)} {}
|
||||
: m_handle{MakeSemaphore(initialCount, maximumCount)} {}
|
||||
~Semaphore() {
|
||||
if (m_handle != 0) {
|
||||
DestroySemaphore(m_handle);
|
||||
|
||||
@@ -6,11 +6,11 @@ extra_includes:
|
||||
- pybind11/stl.h
|
||||
|
||||
functions:
|
||||
CreateEvent:
|
||||
MakeEvent:
|
||||
DestroyEvent:
|
||||
SetEvent:
|
||||
ResetEvent:
|
||||
CreateSemaphore:
|
||||
MakeSemaphore:
|
||||
DestroySemaphore:
|
||||
ReleaseSemaphore:
|
||||
param_override:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# autogenerated by 'semiwrap create-imports wpiutil.sync wpiutil._wpiutil.sync'
|
||||
from .._wpiutil.sync import (
|
||||
createEvent,
|
||||
createSemaphore,
|
||||
makeEvent,
|
||||
makeSemaphore,
|
||||
createSignalObject,
|
||||
destroyEvent,
|
||||
destroySemaphore,
|
||||
@@ -16,8 +16,8 @@ from .._wpiutil.sync import (
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"createEvent",
|
||||
"createSemaphore",
|
||||
"makeEvent",
|
||||
"makeSemaphore",
|
||||
"createSignalObject",
|
||||
"destroyEvent",
|
||||
"destroySemaphore",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(EventTest, AutoReset) {
|
||||
auto event = wpi::util::CreateEvent(false, false);
|
||||
auto event = wpi::util::MakeEvent(false, false);
|
||||
std::thread thr([&] { wpi::util::SetEvent(event); });
|
||||
wpi::util::WaitForObject(event);
|
||||
thr.join();
|
||||
@@ -19,7 +19,7 @@ TEST(EventTest, AutoReset) {
|
||||
}
|
||||
|
||||
TEST(EventTest, ManualReset) {
|
||||
auto event = wpi::util::CreateEvent(true, false);
|
||||
auto event = wpi::util::MakeEvent(true, false);
|
||||
int done = 0;
|
||||
std::thread thr([&] {
|
||||
wpi::util::SetEvent(event);
|
||||
@@ -34,15 +34,15 @@ TEST(EventTest, ManualReset) {
|
||||
}
|
||||
|
||||
TEST(EventTest, InitialSet) {
|
||||
auto event = wpi::util::CreateEvent(false, true);
|
||||
auto event = wpi::util::MakeEvent(false, true);
|
||||
bool timedOut;
|
||||
wpi::util::WaitForObject(event, 0, &timedOut);
|
||||
ASSERT_EQ(timedOut, false);
|
||||
}
|
||||
|
||||
TEST(EventTest, WaitMultiple) {
|
||||
auto event1 = wpi::util::CreateEvent(false, false);
|
||||
auto event2 = wpi::util::CreateEvent(false, false);
|
||||
auto event1 = wpi::util::MakeEvent(false, false);
|
||||
auto event2 = wpi::util::MakeEvent(false, false);
|
||||
std::thread thr([&] { wpi::util::SetEvent(event2); });
|
||||
WPI_Handle signaled[2];
|
||||
auto result1 = wpi::util::WaitForObjects({event1, event2}, signaled);
|
||||
|
||||
Reference in New Issue
Block a user