nvidia-texture-tools/src/nvthread/Event.cpp

71 lines
1.0 KiB
C++
Raw Normal View History

2011-09-27 17:48:46 +00:00
// 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 {
2011-09-27 18:12:32 +00:00
HANDLE handle;
2011-09-27 17:48:46 +00:00
};
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);
}
2012-02-14 18:00:47 +00:00
#elif NV_OS_UNIX
// @@ TODO
#pragma NV_MESSAGE("Implement event using pthreads!")
struct Event::Private {
};
Event::Event() : m(new Private) {
}
Event::~Event() {
}
void Event::post() {
}
void Event::wait() {
}
#endif
2011-09-27 17:48:46 +00:00
/*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) {
2012-02-14 18:00:47 +00:00
// @@ Use wait for multiple objects in win32?
2011-09-27 17:48:46 +00:00
for (uint i = 0; i < count; i++) {
events[i].wait();
}
}