X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fthread%2Fsem_timedwait.c;h=8132eb1bf7a276d9b2dd2c9c978bbc0f0b29b7f4;hb=7c709f2d4f9872d1b445f760b0e68da89e256b9e;hp=b5a60addb0aa7fc398f7a9d7ea93f504d4da16ee;hpb=f5fb20b0e934770c37093105524ea644dcaba5e2;p=musl diff --git a/src/thread/sem_timedwait.c b/src/thread/sem_timedwait.c index b5a60add..8132eb1b 100644 --- a/src/thread/sem_timedwait.c +++ b/src/thread/sem_timedwait.c @@ -8,6 +8,8 @@ static void cleanup(void *p) int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at) { + pthread_testcancel(); + if (!sem_trywait(sem)) return 0; int spins = 100; @@ -17,9 +19,10 @@ int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at) int r; a_inc(sem->__val+1); a_cas(sem->__val, 0, -1); - r = __timedwait(sem->__val, -1, CLOCK_REALTIME, at, cleanup, sem->__val+1, sem->__val[2]); - a_dec(sem->__val+1); - if (r) { + pthread_cleanup_push(cleanup, (void *)(sem->__val+1)); + r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]); + pthread_cleanup_pop(1); + if (r && r != EINTR) { errno = r; return -1; }