diff options
author | Chris Robinson <[email protected]> | 2014-05-01 14:15:31 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-05-01 14:15:31 -0700 |
commit | d90f684f162d4b91a58b61bb2a60ec1257c1dd70 (patch) | |
tree | aa209d2a153ddb4574b86bc31c9a8060531bb90a /Alc | |
parent | 804b08e0ca7931c304d6a2686b036a397cb65b0e (diff) |
Use a backup in case pthread_mutex_timedlock isn't available
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/threads.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Alc/threads.c b/Alc/threads.c index 81db4297..0325c104 100644 --- a/Alc/threads.c +++ b/Alc/threads.c @@ -447,7 +447,10 @@ void almtx_destroy(almtx_t *mtx) int almtx_timedlock(almtx_t *mtx, const struct timespec *ts) { - int ret = pthread_mutex_timedlock(mtx, ts); + int ret; + +#ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK + ret = pthread_mutex_timedlock(mtx, ts); switch(ret) { case 0: return althrd_success; @@ -455,6 +458,25 @@ int almtx_timedlock(almtx_t *mtx, const struct timespec *ts) case EBUSY: return althrd_busy; } return althrd_error; +#else + if(!mtx || !ts) + return althrd_error; + + while((ret=almtx_trylock(mtx)) == althrd_busy) + { + struct timespec now; + + if(ts->tv_sec < 0 || ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000 || + altimespec_get(&now, AL_TIME_UTC) != AL_TIME_UTC) + return althrd_error; + if(now.tv_sec > ts->tv_sec || (now.tv_sec == ts->tv_sec && now.tv_nsec >= ts->tv_nsec)) + return althrd_timedout; + + althrd_yield(); + } + + return ret; +#endif } |