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

Unified Diff: fusl/src/thread/__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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/thread/__syscall_cp.c ('k') | fusl/src/thread/__tls_get_addr.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/thread/__timedwait.c
diff --git a/fusl/src/thread/__timedwait.c b/fusl/src/thread/__timedwait.c
new file mode 100644
index 0000000000000000000000000000000000000000..13d8465a450552bf418f05ac06a3d81176c5b118
--- /dev/null
+++ b/fusl/src/thread/__timedwait.c
@@ -0,0 +1,46 @@
+#include <pthread.h>
+#include <time.h>
+#include <errno.h>
+#include "futex.h"
+#include "syscall.h"
+#include "pthread_impl.h"
+
+int __pthread_setcancelstate(int, int *);
+int __clock_gettime(clockid_t, struct timespec *);
+
+int __timedwait_cp(volatile int *addr, int val,
+ clockid_t clk, const struct timespec *at, int priv)
+{
+ int r;
+ struct timespec to, *top=0;
+
+ if (priv) priv = 128;
+
+ if (at) {
+ if (at->tv_nsec >= 1000000000UL) return EINVAL;
+ if (__clock_gettime(clk, &to)) return EINVAL;
+ to.tv_sec = at->tv_sec - to.tv_sec;
+ if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) {
+ to.tv_sec--;
+ to.tv_nsec += 1000000000;
+ }
+ if (to.tv_sec < 0) return ETIMEDOUT;
+ top = &to;
+ }
+
+ r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT|priv, val, top);
+ if (r == ENOSYS) r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT, val, top);
+ if (r != EINTR && r != ETIMEDOUT && r != ECANCELED) r = 0;
+
+ return r;
+}
+
+int __timedwait(volatile int *addr, int val,
+ clockid_t clk, const struct timespec *at, int priv)
+{
+ int cs, r;
+ __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+ r = __timedwait_cp(addr, val, clk, at, priv);
+ __pthread_setcancelstate(cs, 0);
+ return r;
+}
« no previous file with comments | « fusl/src/thread/__syscall_cp.c ('k') | fusl/src/thread/__tls_get_addr.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698