mirror of https://github.com/encounter/SDL.git
pthread: fix error code checks (thanks, Andreas!).
Most pthread functions return 0 on success and non-zero on error, but those errors might be positive or negative, so checking for return values in the Unix style, where errors are less than zero, is a bug. Fixes Bugzilla #4039.
This commit is contained in:
parent
2ea4419a57
commit
75a58303a0
|
@ -42,7 +42,7 @@ SDL_CreateCond(void)
|
||||||
|
|
||||||
cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
|
cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
|
||||||
if (cond) {
|
if (cond) {
|
||||||
if (pthread_cond_init(&cond->cond, NULL) < 0) {
|
if (pthread_cond_init(&cond->cond, NULL) != 0) {
|
||||||
SDL_SetError("pthread_cond_init() failed");
|
SDL_SetError("pthread_cond_init() failed");
|
||||||
SDL_free(cond);
|
SDL_free(cond);
|
||||||
cond = NULL;
|
cond = NULL;
|
||||||
|
|
|
@ -105,7 +105,7 @@ SDL_LockMutex(SDL_mutex * mutex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (pthread_mutex_lock(&mutex->id) < 0) {
|
if (pthread_mutex_lock(&mutex->id) != 0) {
|
||||||
return SDL_SetError("pthread_mutex_lock() failed");
|
return SDL_SetError("pthread_mutex_lock() failed");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -181,7 +181,7 @@ SDL_UnlockMutex(SDL_mutex * mutex)
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (pthread_mutex_unlock(&mutex->id) < 0) {
|
if (pthread_mutex_unlock(&mutex->id) != 0) {
|
||||||
return SDL_SetError("pthread_mutex_unlock() failed");
|
return SDL_SetError("pthread_mutex_unlock() failed");
|
||||||
}
|
}
|
||||||
#endif /* FAKE_RECURSIVE_MUTEX */
|
#endif /* FAKE_RECURSIVE_MUTEX */
|
||||||
|
|
|
@ -212,7 +212,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||||
int policy;
|
int policy;
|
||||||
pthread_t thread = pthread_self();
|
pthread_t thread = pthread_self();
|
||||||
|
|
||||||
if (pthread_getschedparam(thread, &policy, &sched) < 0) {
|
if (pthread_getschedparam(thread, &policy, &sched) != 0) {
|
||||||
return SDL_SetError("pthread_getschedparam() failed");
|
return SDL_SetError("pthread_getschedparam() failed");
|
||||||
}
|
}
|
||||||
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
||||||
|
@ -224,7 +224,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||||
int max_priority = sched_get_priority_max(policy);
|
int max_priority = sched_get_priority_max(policy);
|
||||||
sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
|
sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
|
||||||
}
|
}
|
||||||
if (pthread_setschedparam(thread, policy, &sched) < 0) {
|
if (pthread_setschedparam(thread, policy, &sched) != 0) {
|
||||||
return SDL_SetError("pthread_setschedparam() failed");
|
return SDL_SetError("pthread_setschedparam() failed");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue