- /* Interrupted FUTEX_WAIT calls may return early.
- *
- * If someone manages to wake the futex while we're spinning
- * around it, we will just return with -1 and errno EWOULDBLOCK,
- * because the value has changed, so that's ok. */
- if (t != 0 && errno == EINTR)
- goto again;
-
- return t;
+ again:
+ if (sec<0) {
+ t = sys_futex(lock_word,FUTEX_WAIT,oldval, 0);
+ }
+ else {
+ timeout.tv_sec = sec;
+ timeout.tv_nsec = usec * 1000;
+ t = sys_futex(lock_word,FUTEX_WAIT,oldval, &timeout);
+ }
+ if (t==0)
+ return 0;
+ else if (errno==ETIMEDOUT)
+ return 1;
+ else if (errno==EINTR)
+ /* spurious wakeup from interrupt */
+ goto again;
+ else
+ /* EWOULDBLOCK and others, need to check the lock */
+ return -1;