SDL_AtomicLock retun int

This commit is contained in:
Sylvain 2023-02-09 09:51:34 +01:00
parent b305d9e3c0
commit 2530d1b3df
No known key found for this signature in database
GPG key ID: 5F87E02E5BC0939E
3 changed files with 20 additions and 6 deletions

View file

@ -117,13 +117,15 @@ extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTryLock(SDL_SpinLock *lock);
* doing. Please be careful using any sort of spinlock!***
*
* \param lock a pointer to a lock variable
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AtomicTryLock
* \sa SDL_AtomicUnlock
*/
extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
extern DECLSPEC int SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
/**
* Unlock a spin lock by setting it to 0.
@ -134,13 +136,15 @@ extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
* doing. Please be careful using any sort of spinlock!***
*
* \param lock a pointer to a lock variable
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AtomicLock
* \sa SDL_AtomicTryLock
*/
extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
extern DECLSPEC int SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
/* @} *//* SDL AtomicLock */

View file

@ -166,9 +166,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
#endif
}
void SDL_AtomicLock(SDL_SpinLock *lock)
int SDL_AtomicLock(SDL_SpinLock *lock)
{
int iterations = 0;
if (lock == NULL) {
return SDL_InvalidParamError("lock");
}
/* FIXME: Should we have an eventual timeout? */
while (!SDL_AtomicTryLock(lock)) {
if (iterations < 32) {
@ -179,10 +183,15 @@ void SDL_AtomicLock(SDL_SpinLock *lock)
SDL_Delay(0);
}
}
return 0;
}
void SDL_AtomicUnlock(SDL_SpinLock *lock)
int SDL_AtomicUnlock(SDL_SpinLock *lock)
{
if (lock == NULL) {
return SDL_InvalidParamError("lock");
}
#if HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
__sync_lock_release(lock);
@ -205,4 +214,5 @@ void SDL_AtomicUnlock(SDL_SpinLock *lock)
#else
*lock = 0;
#endif
return 0;
}

View file

@ -127,11 +127,11 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicCAS,(SDL_atomic_t *a, int b, int c),(a,b,c),r
SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicCASPtr,(void **a, void *b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_AtomicGet,(SDL_atomic_t *a),(a),return)
SDL_DYNAPI_PROC(void*,SDL_AtomicGetPtr,(void **a),(a),return)
SDL_DYNAPI_PROC(void,SDL_AtomicLock,(SDL_SpinLock *a),(a),)
SDL_DYNAPI_PROC(int,SDL_AtomicLock,(SDL_SpinLock *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_AtomicSet,(SDL_atomic_t *a, int b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_AtomicSetPtr,(void **a, void *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicTryLock,(SDL_SpinLock *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_AtomicUnlock,(SDL_SpinLock *a),(a),)
SDL_DYNAPI_PROC(int,SDL_AtomicUnlock,(SDL_SpinLock *a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_AttachVirtualJoystick,(SDL_JoystickType a, int b, int c, int d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_AttachVirtualJoystickEx,(const SDL_VirtualJoystickDesc *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_BlitSurface,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)