You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nvidia-texture-tools/src/nvthread/Event.cpp

54 lines
906 B
C++

// This code is in the public domain -- castano@gmail.com
#include "Event.h"
#if NV_OS_WIN32
#include "Win32.h"
#elif NV_OS_UNIX
#include <pthread.h>
#endif
using namespace nv;
#if NV_OS_WIN32
struct Event::Private {
HANDLE handle;
};
Event::Event() : m(new Private) {
m->handle = CreateEvent(NULL, FALSE, FALSE, NULL);
}
Event::~Event() {
CloseHandle(m->handle);
}
void Event::post() {
SetEvent(m->handle);
}
void Event::wait() {
WaitForSingleObject(m->handle, INFINITE);
}
/*static*/ void Event::post(Event * events, uint count) {
for (uint i = 0; i < count; i++) {
events[i].post();
}
}
/*static*/ void Event::wait(Event * events, uint count) {
// @@ Use wait for multiple objects?
for (uint i = 0; i < count; i++) {
events[i].wait();
}
}
#elif NV_OS_UNIX
// @@ TODO
#pragma NV_MESSAGE("Implement event using pthreads!")
#endif