Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wpiutil] Rename create event and semaphore #7336

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ntcoreffi/src/main/native/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,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
Expand Down
3 changes: 2 additions & 1 deletion wpilibcExamples/src/main/cpp/examples/HAL/c/Robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ that want even more control over what code runs on their robot.
#include <stdio.h>

#include <hal/HAL.h>
#include <wpi/Synchronization.h>

enum DriverStationMode {
DisabledMode,
Expand Down Expand Up @@ -86,7 +87,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ public static AllianceStationID getRawAllianceStation() {
* @return true if connected, false if timeout
*/
public static boolean waitForDsConnection(double timeoutSeconds) {
int event = WPIUtilJNI.createEvent(true, false);
int event = WPIUtilJNI.makeEvent(true, false);
DriverStationJNI.provideNewDataEventHandle(event);
boolean result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DriverStationModeThread() {
}

private void run() {
int handle = WPIUtilJNI.createEvent(false, false);
int handle = WPIUtilJNI.makeEvent(false, false);
DriverStationJNI.provideNewDataEventHandle(handle);

while (m_keepAlive.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static void setMatchTime(double matchTime) {

/** 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void test() {
public void startCompetition() {
DriverStationModeThread modeThread = new DriverStationModeThread();

int event = WPIUtilJNI.createEvent(false, false);
int event = WPIUtilJNI.makeEvent(false, false);

DriverStation.provideRefreshedDataEventHandle(event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void test() {}
public void startCompetition() {
DriverStationModeThread modeThread = new DriverStationModeThread();

int event = WPIUtilJNI.createEvent(false, false);
int event = WPIUtilJNI.makeEvent(false, false);

DriverStation.provideRefreshedDataEventHandle(event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void test() {
public void startCompetition() {
DriverStationModeThread modeThread = new DriverStationModeThread();

int event = WPIUtilJNI.createEvent(false, false);
int event = WPIUtilJNI.makeEvent(false, false);

DriverStation.provideRefreshedDataEventHandle(event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void test() {
public void startCompetition() {
DriverStationModeThread modeThread = new DriverStationModeThread();

int event = WPIUtilJNI.createEvent(false, false);
int event = WPIUtilJNI.makeEvent(false, false);

DriverStation.provideRefreshedDataEventHandle(event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected Logger getClassLogger() {
public void waitForDataTest() {
long startTime = RobotController.getFPGATime();

int handle = WPIUtilJNI.createEvent(false, false);
int handle = WPIUtilJNI.makeEvent(false, false);
DriverStationJNI.provideNewDataEventHandle(handle);

// Wait for data 50 times
Expand Down
2 changes: 1 addition & 1 deletion wpinet/src/main/native/macOS/ResolverThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void ResolverThread::RemoveServiceRefInThread(DNSServiceRef serviceRef) {
WPI_EventHandle ResolverThread::RemoveServiceRefOutsideThread(
DNSServiceRef serviceRef) {
std::scoped_lock lock{serviceRefMutex};
WPI_EventHandle handle = CreateEvent(true);
WPI_EventHandle handle = MakeEvent(true);
serviceRefsToRemove.push_back({serviceRef, handle});
return handle;
}
Expand Down
4 changes: 2 additions & 2 deletions wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static synchronized void forceLoad() throws IOException {
* @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.
Expand Down Expand Up @@ -141,7 +141,7 @@ public static synchronized void forceLoad() throws IOException {
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions wpiutil/src/main/native/cpp/Synchronization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static HandleManager& GetManager() {
return manager;
}

WPI_EventHandle wpi::CreateEvent(bool manualReset, bool initialState) {
WPI_EventHandle wpi::MakeEvent(bool manualReset, bool initialState) {
auto& manager = GetManager();
if (gShutdown) {
return {};
Expand Down Expand Up @@ -92,7 +92,7 @@ void wpi::ResetEvent(WPI_EventHandle handle) {
ResetSignalObject(handle);
}

WPI_SemaphoreHandle wpi::CreateSemaphore(int initialCount, int maximumCount) {
WPI_SemaphoreHandle wpi::MakeSemaphore(int initialCount, int maximumCount) {
auto& manager = GetManager();
if (gShutdown) {
return {};
Expand Down Expand Up @@ -325,8 +325,8 @@ void wpi::DestroySignalObject(WPI_Handle handle) {

extern "C" {

WPI_EventHandle WPI_CreateEvent(int manual_reset, int initial_state) {
return wpi::CreateEvent(manual_reset != 0, initial_state != 0);
WPI_EventHandle WPI_MakeEvent(int manual_reset, int initial_state) {
return wpi::MakeEvent(manual_reset != 0, initial_state != 0);
}

void WPI_DestroyEvent(WPI_EventHandle handle) {
Expand All @@ -341,8 +341,8 @@ void WPI_ResetEvent(WPI_EventHandle handle) {
wpi::ResetEvent(handle);
}

WPI_SemaphoreHandle WPI_CreateSemaphore(int initial_count, int maximum_count) {
return wpi::CreateSemaphore(initial_count, maximum_count);
WPI_SemaphoreHandle WPI_MakeSemaphore(int initial_count, int maximum_count) {
return wpi::MakeSemaphore(initial_count, maximum_count);
}

void WPI_DestroySemaphore(WPI_SemaphoreHandle handle) {
Expand Down
12 changes: 6 additions & 6 deletions wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ Java_edu_wpi_first_util_WPIUtilJNI_getSystemTime

/*
* Class: edu_wpi_first_util_WPIUtilJNI
* Method: createEvent
* Method: makeEvent
* Signature: (ZZ)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_util_WPIUtilJNI_createEvent
Java_edu_wpi_first_util_WPIUtilJNI_makeEvent
(JNIEnv*, jclass, jboolean manualReset, jboolean initialState)
{
return wpi::CreateEvent(manualReset, initialState);
return wpi::MakeEvent(manualReset, initialState);
}

/*
Expand Down Expand Up @@ -210,14 +210,14 @@ Java_edu_wpi_first_util_WPIUtilJNI_resetEvent

/*
* Class: edu_wpi_first_util_WPIUtilJNI
* Method: createSemaphore
* Method: makeSemaphore
* Signature: (II)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_util_WPIUtilJNI_createSemaphore
Java_edu_wpi_first_util_WPIUtilJNI_makeSemaphore
(JNIEnv*, jclass, jint initialCount, jint maximumCount)
{
return wpi::CreateSemaphore(initialCount, maximumCount);
return wpi::MakeSemaphore(initialCount, maximumCount);
}

/*
Expand Down
15 changes: 7 additions & 8 deletions wpiutil/src/main/native/include/wpi/Synchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ constexpr int kHandleTypeUserBase = 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.
Expand Down Expand Up @@ -93,8 +92,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.
Expand Down Expand Up @@ -256,7 +255,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);
Expand Down Expand Up @@ -321,7 +320,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);
Expand Down Expand Up @@ -460,7 +459,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.
Expand Down Expand Up @@ -494,7 +493,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.
Expand Down
10 changes: 5 additions & 5 deletions wpiutil/src/test/native/cpp/SynchronizationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <gtest/gtest.h>

TEST(EventTest, AutoReset) {
auto event = wpi::CreateEvent(false, false);
auto event = wpi::MakeEvent(false, false);
std::thread thr([&] { wpi::SetEvent(event); });
wpi::WaitForObject(event);
thr.join();
Expand All @@ -19,7 +19,7 @@ TEST(EventTest, AutoReset) {
}

TEST(EventTest, ManualReset) {
auto event = wpi::CreateEvent(true, false);
auto event = wpi::MakeEvent(true, false);
int done = 0;
std::thread thr([&] {
wpi::SetEvent(event);
Expand All @@ -34,15 +34,15 @@ TEST(EventTest, ManualReset) {
}

TEST(EventTest, InitialSet) {
auto event = wpi::CreateEvent(false, true);
auto event = wpi::MakeEvent(false, true);
bool timedOut;
wpi::WaitForObject(event, 0, &timedOut);
ASSERT_EQ(timedOut, false);
}

TEST(EventTest, WaitMultiple) {
auto event1 = wpi::CreateEvent(false, false);
auto event2 = wpi::CreateEvent(false, false);
auto event1 = wpi::MakeEvent(false, false);
auto event2 = wpi::MakeEvent(false, false);
std::thread thr([&] { wpi::SetEvent(event2); });
WPI_Handle signaled[2];
auto result1 = wpi::WaitForObjects({event1, event2}, signaled);
Expand Down
Loading