| OLD | NEW |
| 1 #include <semaphore.h> | 1 #include <semaphore.h> |
| 2 #include "pthread_impl.h" | 2 #include "pthread_impl.h" |
| 3 | 3 |
| 4 static void cleanup(void *p) | 4 static void cleanup(void* p) { |
| 5 { | 5 a_dec(p); |
| 6 » a_dec(p); | |
| 7 } | 6 } |
| 8 | 7 |
| 9 int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at) | 8 int sem_timedwait(sem_t* restrict sem, const struct timespec* restrict at) { |
| 10 { | 9 pthread_testcancel(); |
| 11 » pthread_testcancel(); | |
| 12 | 10 |
| 13 » if (!sem_trywait(sem)) return 0; | 11 if (!sem_trywait(sem)) |
| 12 return 0; |
| 14 | 13 |
| 15 » int spins = 100; | 14 int spins = 100; |
| 16 » while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) a_spin(); | 15 while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) |
| 16 a_spin(); |
| 17 | 17 |
| 18 » while (sem_trywait(sem)) { | 18 while (sem_trywait(sem)) { |
| 19 » » int r; | 19 int r; |
| 20 » » a_inc(sem->__val+1); | 20 a_inc(sem->__val + 1); |
| 21 » » a_cas(sem->__val, 0, -1); | 21 a_cas(sem->__val, 0, -1); |
| 22 » » pthread_cleanup_push(cleanup, (void *)(sem->__val+1)); | 22 pthread_cleanup_push(cleanup, (void*)(sem->__val + 1)); |
| 23 » » r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__va
l[2]); | 23 r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]); |
| 24 » » pthread_cleanup_pop(1); | 24 pthread_cleanup_pop(1); |
| 25 » » if (r && r != EINTR) { | 25 if (r && r != EINTR) { |
| 26 » » » errno = r; | 26 errno = r; |
| 27 » » » return -1; | 27 return -1; |
| 28 » » } | 28 } |
| 29 » } | 29 } |
| 30 » return 0; | 30 return 0; |
| 31 } | 31 } |
| OLD | NEW |