| | |
| | | SDL_TryLockMutex(SDL_mutex * mutex) |
| | | { |
| | | int retval; |
| | | int result; |
| | | #if FAKE_RECURSIVE_MUTEX |
| | | pthread_t this_thread; |
| | | #endif |
| | |
| | | We set the locking thread id after we obtain the lock |
| | | so unlocks from other threads will fail. |
| | | */ |
| | | if (pthread_mutex_trylock(&mutex->id) == 0) { |
| | | result = pthread_mutex_trylock(&mutex->id); |
| | | if (result == 0) { |
| | | mutex->owner = this_thread; |
| | | mutex->recursive = 0; |
| | | } else if (errno == EBUSY) { |
| | | } else if (result == EBUSY) { |
| | | retval = SDL_MUTEX_TIMEDOUT; |
| | | } else { |
| | | retval = SDL_SetError("pthread_mutex_trylock() failed"); |
| | | } |
| | | } |
| | | #else |
| | | if (pthread_mutex_trylock(&mutex->id) != 0) { |
| | | if (errno == EBUSY) { |
| | | result = pthread_mutex_trylock(&mutex->id); |
| | | if (result != 0) { |
| | | if (result == EBUSY) { |
| | | retval = SDL_MUTEX_TIMEDOUT; |
| | | } else { |
| | | retval = SDL_SetError("pthread_mutex_trylock() failed"); |