Wiki Page Content

Differences between revisions 1 and 2
Revision 1 as of 2010-06-02 01:17:01
Size: 1056
Editor: SheenaSmith
Comment: create page, add content (Wed Mar 10 ver; changeset 4428)
Revision 2 as of 2010-09-09 21:27:13
Size: 2189
Editor: SheenaSmith
Comment: update content (old wiki)
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
Use this function ,,to,, ^as a^ variant of [[SDL_SemWait]]() with a timeout in milliseconds. Use this function to *lock a semaphore* ^with a timeout^ ''-or-'' ^as a^ variant of [[SDL_SemWait]]() with a timeout in milliseconds.
Line 21: Line 21:
Returns 0 if the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in the allotted time, and -1 on error; call [[SDL_GetError]]() for more information. 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.

*<<BR>>If the semaphore was not successfully locked, the semaphore will be unchanged.<<BR>>*
Line 24: Line 26:
*
Line 25: Line 28:
You can add your code example here 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);
Line 27: Line 41:
*<<BR>><<Color2(green,Note that the 1.2 ver used a different param so this example should be checked for compliance with the current syntax.)>>
Line 29: Line 44:
/!\ {i} On some platforms this function is implemented by looping with a delay of 1 ms, and so should be avoided if possible. On some platforms this function is implemented by looping with a delay of 1 ms, and so should be avoided if possible.

*<<BR>>[[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]]().<<BR>>*
Line 32: Line 51:
 .[[SDL_SemTryWait]] ???
 .[[SDL_SemWait]]
 .[[SDL_SemPost]] *
.[[SDL_SemTryWait]] *
 .[[SDL_SemValue]] *

 .[[SDL_SemWait]] *

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

a pointer to the SDL_sem structure 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