| 54 | } |
| 55 | |
| 56 | bool Semaphore::acquire(bool block, S32 timeoutMS) |
| 57 | { |
| 58 | AssertFatal(mData && mData->semaphore, "Semaphore::acquire - Invalid semaphore."); |
| 59 | if (block) |
| 60 | { |
| 61 | // Semaphore acquiring is different from the MacOS/Win realization because SDL_SemWaitTimeout() with "infinite" timeout can be too heavy on some platforms. |
| 62 | // (see "man SDL_SemWaitTimeout(3)" for more info) |
| 63 | // "man" states to avoid the use of SDL_SemWaitTimeout at all, but at current stage this looks like a valid and working solution, so keeping it this way. |
| 64 | // [bank / Feb-2010] |
| 65 | if (timeoutMS == -1) |
| 66 | { |
| 67 | if (SDL_SemWait(mData->semaphore) < 0) |
| 68 | AssertFatal(false, "Semaphore::acquie - Wait failed."); |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | if (SDL_SemWaitTimeout(mData->semaphore, timeoutMS) < 0) |
| 73 | AssertFatal(false, "Semaphore::acquie - Wait with timeout failed."); |
| 74 | } |
| 75 | return (true); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | int res = SDL_SemTryWait(mData->semaphore); |
| 80 | return (res == 0); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void Semaphore::release() |
| 85 | { |
no test coverage detected