Wiki Page Content

Differences between revisions 3 and 4
Revision 3 as of 2010-10-12 06:05:28
Size: 2166
Editor: SheenaSmith
Comment: update content - pointers, structs
Revision 4 as of 2010-10-18 02:14:40
Size: 2168
Editor: SheenaSmith
Comment: update contents - pointers, structs
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
||'''sem'''||^the SDL_sem to monitor^|| ||'''sem'''||^the semaphore to monitor^||

DRAFT

SDL_SemWaitTimeout

Use this function to *lock a semaphore* with a timeout -or- as a variant of SDL_SemWait() with a timeout in milliseconds.

Syntax

int SDL_SemWaitTimeout(SDL_sem* sem,
                       Uint32   ms)

Function Parameters

sem

the semaphore to monitor

ms

the length of the timeout in milliseconds

Return Value

Returns 0 if the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in the allotted time, or a negative error code on failure; call SDL_GetError() for more information.

*
If the semaphore was not successfully locked, the semaphore will be unchanged.
*

Code Examples

*

res = SDL_SemWaitTimeout(my_sem, WAIT_TIMEOUT_MILLISEC);

if (res == SDL_MUTEX_TIMEDOUT) {
        return TRY_AGAIN;
}
if (res == -1) {
        return WAIT_ERROR;
}

...

SDL_SemPost(my_sem);

*
green

Remarks

On some platforms this function is implemented by looping with a delay of 1 ms, and so should be avoided if possible.

*
SDL_SemWaitTimeout() is a variant of SDL_SemWait() with a maximum timeout value. If the value of the semaphore pointed to by sem is positive, it will atomically decrement the semaphore value and return 0, otherwise it will wait up to ms milliseconds trying to lock the semaphore. This function is to be avoided if possible since on some platforms it is implemented by polling the semaphore every millisecond in a busy loop.

After SDL_SemWaitTimeout() is successful, the semaphore can be released and its count atomically incremented by a successful call to SDL_SemPost().
*


CategoryAPI, CategoryMutex

None: SDL_SemWaitTimeout (last edited 2013-10-05 19:38:17 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit