thread: Locking mutexes and rwlocks are now void functions.
Almost nothing checks these return values, and there's no reason a valid lock should fail to operate. The cases where a lock isn't valid (it's a bogus pointer, it was previously destroyed, a thread is unlocking a lock it doesn't own, etc) are undefined behavior and always were, and should be treated as an application bug. Reference Issue #8096.
This commit is contained in:
parent
082ef41566
commit
899eb0d042
21 changed files with 496 additions and 746 deletions
|
@ -123,17 +123,16 @@ SDL_PropertiesID SDL_CreateProperties(void)
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (SDL_LockRWLockForWriting(SDL_properties_lock) == 0) {
|
||||
SDL_LockRWLockForWriting(SDL_properties_lock);
|
||||
++SDL_last_properties_id;
|
||||
if (SDL_last_properties_id == 0) {
|
||||
++SDL_last_properties_id;
|
||||
if (SDL_last_properties_id == 0) {
|
||||
++SDL_last_properties_id;
|
||||
}
|
||||
props = SDL_last_properties_id;
|
||||
if (SDL_InsertIntoHashTable(SDL_properties, (const void *)(uintptr_t)props, properties)) {
|
||||
inserted = SDL_TRUE;
|
||||
}
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
}
|
||||
props = SDL_last_properties_id;
|
||||
if (SDL_InsertIntoHashTable(SDL_properties, (const void *)(uintptr_t)props, properties)) {
|
||||
inserted = SDL_TRUE;
|
||||
}
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
|
||||
if (inserted) {
|
||||
/* All done! */
|
||||
|
@ -152,15 +151,17 @@ int SDL_LockProperties(SDL_PropertiesID props)
|
|||
if (!props) {
|
||||
return SDL_InvalidParamError("props");
|
||||
}
|
||||
if (SDL_LockRWLockForReading(SDL_properties_lock) == 0) {
|
||||
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
}
|
||||
|
||||
SDL_LockRWLockForReading(SDL_properties_lock);
|
||||
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
SDL_InvalidParamError("props");
|
||||
return -1;
|
||||
return SDL_InvalidParamError("props");
|
||||
}
|
||||
return SDL_LockMutex(properties->lock);
|
||||
|
||||
SDL_LockMutex(properties->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SDL_UnlockProperties(SDL_PropertiesID props)
|
||||
|
@ -170,13 +171,15 @@ void SDL_UnlockProperties(SDL_PropertiesID props)
|
|||
if (!props) {
|
||||
return;
|
||||
}
|
||||
if (SDL_LockRWLockForReading(SDL_properties_lock) == 0) {
|
||||
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
}
|
||||
|
||||
SDL_LockRWLockForReading(SDL_properties_lock);
|
||||
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_UnlockMutex(properties->lock);
|
||||
}
|
||||
|
||||
|
@ -193,10 +196,10 @@ int SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value, void
|
|||
return SDL_InvalidParamError("name");
|
||||
}
|
||||
|
||||
if (SDL_LockRWLockForReading(SDL_properties_lock) == 0) {
|
||||
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
}
|
||||
SDL_LockRWLockForReading(SDL_properties_lock);
|
||||
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
return SDL_InvalidParamError("props");
|
||||
}
|
||||
|
@ -242,10 +245,10 @@ void *SDL_GetProperty(SDL_PropertiesID props, const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (SDL_LockRWLockForReading(SDL_properties_lock) == 0) {
|
||||
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
}
|
||||
SDL_LockRWLockForReading(SDL_properties_lock);
|
||||
SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
|
||||
if (!properties) {
|
||||
SDL_InvalidParamError("props");
|
||||
return NULL;
|
||||
|
@ -280,8 +283,7 @@ void SDL_DestroyProperties(SDL_PropertiesID props)
|
|||
return;
|
||||
}
|
||||
|
||||
if (SDL_LockRWLockForWriting(SDL_properties_lock) == 0) {
|
||||
SDL_RemoveFromHashTable(SDL_properties, (const void *)(uintptr_t)props);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
}
|
||||
SDL_LockRWLockForWriting(SDL_properties_lock);
|
||||
SDL_RemoveFromHashTable(SDL_properties, (const void *)(uintptr_t)props);
|
||||
SDL_UnlockRWLock(SDL_properties_lock);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue