Updated the atomic API for SDL 3.0 naming conventions
Fixes https://github.com/libsdl-org/SDL/issues/7388
This commit is contained in:
parent
4e60fc9b2b
commit
a2665f54c8
24 changed files with 156 additions and 112 deletions
|
@ -122,17 +122,17 @@ SDL_TLSData *SDL_Generic_GetTLSData(void)
|
|||
#ifndef SDL_THREADS_DISABLED
|
||||
if (!SDL_generic_TLS_mutex) {
|
||||
static SDL_SpinLock tls_lock;
|
||||
SDL_AtomicLock(&tls_lock);
|
||||
SDL_LockSpinlock(&tls_lock);
|
||||
if (!SDL_generic_TLS_mutex) {
|
||||
SDL_Mutex *mutex = SDL_CreateMutex();
|
||||
SDL_MemoryBarrierRelease();
|
||||
SDL_generic_TLS_mutex = mutex;
|
||||
if (!SDL_generic_TLS_mutex) {
|
||||
SDL_AtomicUnlock(&tls_lock);
|
||||
SDL_UnlockSpinlock(&tls_lock);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
SDL_AtomicUnlock(&tls_lock);
|
||||
SDL_UnlockSpinlock(&tls_lock);
|
||||
}
|
||||
SDL_MemoryBarrierAcquire();
|
||||
SDL_LockMutex(SDL_generic_TLS_mutex);
|
||||
|
@ -232,7 +232,7 @@ SDL_error *SDL_GetErrBuf(SDL_bool create)
|
|||
but that's very unlikely and hopefully won't cause issues.
|
||||
*/
|
||||
if (!tls_errbuf && !tls_being_created) {
|
||||
SDL_AtomicLock(&tls_lock);
|
||||
SDL_LockSpinlock(&tls_lock);
|
||||
if (!tls_errbuf) {
|
||||
SDL_TLSID slot;
|
||||
tls_being_created = SDL_TRUE;
|
||||
|
@ -241,7 +241,7 @@ SDL_error *SDL_GetErrBuf(SDL_bool create)
|
|||
SDL_MemoryBarrierRelease();
|
||||
tls_errbuf = slot;
|
||||
}
|
||||
SDL_AtomicUnlock(&tls_lock);
|
||||
SDL_UnlockSpinlock(&tls_lock);
|
||||
}
|
||||
if (!tls_errbuf) {
|
||||
return SDL_GetStaticErrBuf();
|
||||
|
@ -296,9 +296,9 @@ void SDL_RunThread(SDL_Thread *thread)
|
|||
SDL_CleanupTLS();
|
||||
|
||||
/* Mark us as ready to be joined (or detached) */
|
||||
if (!SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_ZOMBIE)) {
|
||||
if (!SDL_AtomicCompareAndSwap(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_ZOMBIE)) {
|
||||
/* Clean up if something already detached us. */
|
||||
if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_CLEANED)) {
|
||||
if (SDL_AtomicCompareAndSwap(&thread->state, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_CLEANED)) {
|
||||
if (thread->name) {
|
||||
SDL_free(thread->name);
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ void SDL_DetachThread(SDL_Thread *thread)
|
|||
}
|
||||
|
||||
/* Grab dibs if the state is alive+joinable. */
|
||||
if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_DETACHED)) {
|
||||
if (SDL_AtomicCompareAndSwap(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_DETACHED)) {
|
||||
SDL_SYS_DetachThread(thread);
|
||||
} else {
|
||||
/* all other states are pretty final, see where we landed. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue