Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: fusl/src/thread/sem_timedwait.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/thread/sem_post.c ('k') | fusl/src/thread/sem_trywait.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <semaphore.h>
2 #include "pthread_impl.h"
3
4 static void cleanup(void *p)
5 {
6 a_dec(p);
7 }
8
9 int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at)
10 {
11 pthread_testcancel();
12
13 if (!sem_trywait(sem)) return 0;
14
15 int spins = 100;
16 while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) a_spin();
17
18 while (sem_trywait(sem)) {
19 int r;
20 a_inc(sem->__val+1);
21 a_cas(sem->__val, 0, -1);
22 pthread_cleanup_push(cleanup, (void *)(sem->__val+1));
23 r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__va l[2]);
24 pthread_cleanup_pop(1);
25 if (r && r != EINTR) {
26 errno = r;
27 return -1;
28 }
29 }
30 return 0;
31 }
OLDNEW
« no previous file with comments | « fusl/src/thread/sem_post.c ('k') | fusl/src/thread/sem_trywait.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698