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

RFC: Rename neosmart_event_t to pevent_t #12

Open
wants to merge 2 commits into
base: master
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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ correct¹.
Linux, and a common pitfall for developers coming from the Windows world.*

```cpp
neosmart_event_t CreateEvent(bool manualReset, bool initialState);
pevent_t CreateEvent(bool manualReset, bool initialState);

int DestroyEvent(neosmart_event_t event);
int DestroyEvent(pevent_t event);

int WaitForEvent(neosmart_event_t event, uint64_t milliseconds);
int WaitForEvent(pevent_t event, uint64_t milliseconds);

int WaitForMultipleEvents(neosmart_event_t *events, int count,
int WaitForMultipleEvents(pevent_t *events, int count,
bool waitAll, uint64_t milliseconds);

int WaitForMultipleEvents(neosmart_event_t *events, int count,
int WaitForMultipleEvents(pevent_t *events, int count,
bool waitAll, uint64_t milliseconds, int &index);

int SetEvent(neosmart_event_t event);
int SetEvent(pevent_t event);

int ResetEvent(neosmart_event_t event);
int ResetEvent(pevent_t event);

int PulseEvent(neosmart_event_t event);
int PulseEvent(pevent_t event);
```

## Building and using pevents
Expand Down
2 changes: 1 addition & 1 deletion examples/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using namespace neosmart;
using namespace std;

neosmart_event_t events[5]; // letters, numbers, abort, letterSync, numberSync
pevent_t events[5]; // letters, numbers, abort, letterSync, numberSync
std::atomic<bool> interrupted{false}; // for signal handling

// By leaving these originally unassigned, any access to unitialized memory
Expand Down
40 changes: 20 additions & 20 deletions src/pevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace neosmart {
#endif // WFMO

// The basic event structure, passed to the caller as an opaque pointer when creating events
struct neosmart_event_t_ {
struct pevent_t_ {
pthread_cond_t CVariable;
pthread_mutex_t Mutex;
bool AutoReset;
Expand Down Expand Up @@ -91,8 +91,8 @@ namespace neosmart {
}
#endif // WFMO

neosmart_event_t CreateEvent(bool manualReset, bool initialState) {
neosmart_event_t event = new neosmart_event_t_;
pevent_t CreateEvent(bool manualReset, bool initialState) {
pevent_t event = new pevent_t_;

int result = pthread_cond_init(&event->CVariable, 0);
assert(result == 0);
Expand All @@ -111,7 +111,7 @@ namespace neosmart {
return event;
}

static int UnlockedWaitForEvent(neosmart_event_t event, uint64_t milliseconds) {
static int UnlockedWaitForEvent(pevent_t event, uint64_t milliseconds) {
int result = 0;
if (!event->State) {
// Zero-timeout event state check optimization
Expand Down Expand Up @@ -157,7 +157,7 @@ namespace neosmart {
return result;
}

int WaitForEvent(neosmart_event_t event, uint64_t milliseconds) {
int WaitForEvent(pevent_t event, uint64_t milliseconds) {
int tempResult;
if (milliseconds == 0) {
tempResult = pthread_mutex_trylock(&event->Mutex);
Expand All @@ -179,13 +179,13 @@ namespace neosmart {
}

#ifdef WFMO
int WaitForMultipleEvents(neosmart_event_t *events, int count, bool waitAll,
int WaitForMultipleEvents(pevent_t *events, int count, bool waitAll,
uint64_t milliseconds) {
int unused;
return WaitForMultipleEvents(events, count, waitAll, milliseconds, unused);
}

int WaitForMultipleEvents(neosmart_event_t *events, int count, bool waitAll,
int WaitForMultipleEvents(pevent_t *events, int count, bool waitAll,
uint64_t milliseconds, int &waitIndex) {
neosmart_wfmo_t wfmo = new neosmart_wfmo_t_;

Expand Down Expand Up @@ -315,7 +315,7 @@ namespace neosmart {
}
#endif // WFMO

int DestroyEvent(neosmart_event_t event) {
int DestroyEvent(pevent_t event) {
int result = 0;

#ifdef WFMO
Expand All @@ -340,7 +340,7 @@ namespace neosmart {
return 0;
}

int SetEvent(neosmart_event_t event) {
int SetEvent(pevent_t event) {
int result = pthread_mutex_lock(&event->Mutex);
assert(result == 0);

Expand Down Expand Up @@ -459,7 +459,7 @@ namespace neosmart {
return 0;
}

int ResetEvent(neosmart_event_t event) {
int ResetEvent(pevent_t event) {
int result = pthread_mutex_lock(&event->Mutex);
assert(result == 0);

Expand All @@ -472,7 +472,7 @@ namespace neosmart {
}

#ifdef PULSE
int PulseEvent(neosmart_event_t event) {
int PulseEvent(pevent_t event) {
// This may look like it's a horribly inefficient kludge with the sole intention of reducing
// code duplication, but in reality this is what any PulseEvent() implementation must look
// like. The only overhead (function calls aside, which your compiler will likely optimize
Expand All @@ -499,16 +499,16 @@ namespace neosmart {
#include "pevents.h"

namespace neosmart {
neosmart_event_t CreateEvent(bool manualReset, bool initialState) {
return static_cast<neosmart_event_t>(::CreateEvent(NULL, manualReset, initialState, NULL));
pevent_t CreateEvent(bool manualReset, bool initialState) {
return static_cast<pevent_t>(::CreateEvent(NULL, manualReset, initialState, NULL));
}

int DestroyEvent(neosmart_event_t event) {
int DestroyEvent(pevent_t event) {
HANDLE handle = static_cast<HANDLE>(event);
return CloseHandle(handle) ? 0 : GetLastError();
}

int WaitForEvent(neosmart_event_t event, uint64_t milliseconds) {
int WaitForEvent(pevent_t event, uint64_t milliseconds) {
uint32_t result = 0;
HANDLE handle = static_cast<HANDLE>(event);

Expand Down Expand Up @@ -539,24 +539,24 @@ namespace neosmart {
return GetLastError();
}

int SetEvent(neosmart_event_t event) {
int SetEvent(pevent_t event) {
HANDLE handle = static_cast<HANDLE>(event);
return ::SetEvent(handle) ? 0 : GetLastError();
}

int ResetEvent(neosmart_event_t event) {
int ResetEvent(pevent_t event) {
HANDLE handle = static_cast<HANDLE>(event);
return ::ResetEvent(handle) ? 0 : GetLastError();
}

#ifdef WFMO
int WaitForMultipleEvents(neosmart_event_t *events, int count, bool waitAll,
int WaitForMultipleEvents(pevent_t *events, int count, bool waitAll,
uint64_t milliseconds) {
int index = 0;
return WaitForMultipleEvents(events, count, waitAll, milliseconds, index);
}

int WaitForMultipleEvents(neosmart_event_t *events, int count, bool waitAll,
int WaitForMultipleEvents(pevent_t *events, int count, bool waitAll,
uint64_t milliseconds, int &index) {
HANDLE *handles = reinterpret_cast<HANDLE *>(events);
uint32_t result = 0;
Expand Down Expand Up @@ -593,7 +593,7 @@ namespace neosmart {
#endif

#ifdef PULSE
int PulseEvent(neosmart_event_t event) {
int PulseEvent(pevent_t event) {
HANDLE handle = static_cast<HANDLE>(event);
return ::PulseEvent(handle) ? 0 : GetLastError();
}
Expand Down
20 changes: 10 additions & 10 deletions src/pevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@

namespace neosmart {
// Type declarations
struct neosmart_event_t_;
typedef neosmart_event_t_ *neosmart_event_t;
struct pevent_t_;
typedef pevent_t_ *pevent_t;

// Constant declarations
const uint64_t WAIT_INFINITE = ~((unsigned long long)0);

// Function declarations
neosmart_event_t CreateEvent(bool manualReset = false, bool initialState = false);
int DestroyEvent(neosmart_event_t event);
int WaitForEvent(neosmart_event_t event, uint64_t milliseconds = WAIT_INFINITE);
int SetEvent(neosmart_event_t event);
int ResetEvent(neosmart_event_t event);
pevent_t CreateEvent(bool manualReset = false, bool initialState = false);
int DestroyEvent(pevent_t event);
int WaitForEvent(pevent_t event, uint64_t milliseconds = WAIT_INFINITE);
int SetEvent(pevent_t event);
int ResetEvent(pevent_t event);
#ifdef WFMO
int WaitForMultipleEvents(neosmart_event_t *events, int count, bool waitAll,
int WaitForMultipleEvents(pevent_t *events, int count, bool waitAll,
uint64_t milliseconds);
int WaitForMultipleEvents(neosmart_event_t *events, int count, bool waitAll,
int WaitForMultipleEvents(pevent_t *events, int count, bool waitAll,
uint64_t milliseconds, int &index);
#endif
#ifdef PULSE
int PulseEvent(neosmart_event_t event);
int PulseEvent(pevent_t event);
#endif
} // namespace neosmart
6 changes: 3 additions & 3 deletions tests/AutoResetBasicTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

using namespace neosmart;

neosmart_event_t event;
neosmart_event_t t1_started;
neosmart_event_t t1_finished;
pevent_t event;
pevent_t t1_started;
pevent_t t1_finished;

void worker() {
WaitForEvent(event, 0);
Expand Down
6 changes: 3 additions & 3 deletions tests/ManualResetBasicTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

using namespace neosmart;

neosmart_event_t event;
neosmart_event_t t1_started;
neosmart_event_t t1_finished;
pevent_t event;
pevent_t t1_started;
pevent_t t1_finished;

void worker() {
WaitForEvent(event, 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/WaitTimeoutAllSignalled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "pevents.h"

int main() {
std::vector<neosmart::neosmart_event_t> lPEvents(63); // Can be any number of events from 1-N.
std::vector<neosmart::pevent_t> lPEvents(63); // Can be any number of events from 1-N.
for (auto &lEvent : lPEvents) {
// Manual or Auto-Reset Events (doesn't matter which kind), and all already set.
//
Expand Down