MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / acquire

Method acquire

Engine/source/platformSDL/threads/semaphore.cpp:56–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56bool 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
84void Semaphore::release()
85{

Callers 2

startMethod · 0.45
joinMethod · 0.45

Calls 3

SDL_SemWaitFunction · 0.50
SDL_SemWaitTimeoutFunction · 0.50
SDL_SemTryWaitFunction · 0.50

Tested by

no test coverage detected