1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #include "semaphore_windows.h"
- #if defined(WINDOWS_ENABLED)
- #include "core/os/memory.h"
- Error SemaphoreWindows::wait() {
- WaitForSingleObjectEx(semaphore, INFINITE, false);
- return OK;
- }
- Error SemaphoreWindows::post() {
- ReleaseSemaphore(semaphore, 1, NULL);
- return OK;
- }
- int SemaphoreWindows::get() const {
- long previous;
- switch (WaitForSingleObjectEx(semaphore, 0, false)) {
- case WAIT_OBJECT_0: {
- ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous), -1);
- return previous + 1;
- } break;
- case WAIT_TIMEOUT: {
- return 0;
- } break;
- default: {}
- }
- ERR_FAIL_V(-1);
- }
- Semaphore *SemaphoreWindows::create_semaphore_windows() {
- return memnew(SemaphoreWindows);
- }
- void SemaphoreWindows::make_default() {
- create_func = create_semaphore_windows;
- }
- SemaphoreWindows::SemaphoreWindows() {
- #ifdef UWP_ENABLED
- semaphore = CreateSemaphoreEx(
- NULL,
- 0,
- 0xFFFFFFF,
- NULL,
- 0,
- SEMAPHORE_ALL_ACCESS);
- #else
- semaphore = CreateSemaphore(
- NULL,
- 0,
- 0xFFFFFFF,
- NULL);
- #endif
- }
- SemaphoreWindows::~SemaphoreWindows() {
- CloseHandle(semaphore);
- }
- #endif
|