[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:
Thad House
2026-03-30 15:54:42 -07:00
committed by GitHub
parent d248c040bf
commit bf218113db
20 changed files with 47 additions and 48 deletions

View File

@@ -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.

View File

@@ -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);
}
/**

View File

@@ -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);
}
/**

View File

@@ -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) {

View File

@@ -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);
}
/*

View File

@@ -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.

View File

@@ -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);

View File

@@ -6,11 +6,11 @@ extra_includes:
- pybind11/stl.h
functions:
CreateEvent:
MakeEvent:
DestroyEvent:
SetEvent:
ResetEvent:
CreateSemaphore:
MakeSemaphore:
DestroySemaphore:
ReleaseSemaphore:
param_override:

View File

@@ -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",

View File

@@ -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);