int compat_futex_noasync(int32_t *uaddr, int op, int32_t val,
const struct timespec *timeout, int32_t *uaddr2, int32_t val3)
{
- int ret, gret = 0;
+ int ret = 0, lockret;
/*
* Check if NULL. Don't let users expect that they are taken into
- * account.
+ * account.
*/
assert(!timeout);
assert(!uaddr2);
*/
cmm_smp_mb();
- ret = pthread_mutex_lock(&__urcu_compat_futex_lock);
- assert(!ret);
+ lockret = pthread_mutex_lock(&__urcu_compat_futex_lock);
+ if (lockret) {
+ errno = lockret;
+ ret = -1;
+ goto end;
+ }
switch (op) {
case FUTEX_WAIT:
/*
pthread_cond_broadcast(&__urcu_compat_futex_cond);
break;
default:
- gret = -EINVAL;
+ errno = EINVAL;
+ ret = -1;
+ }
+ lockret = pthread_mutex_unlock(&__urcu_compat_futex_lock);
+ if (lockret) {
+ errno = lockret;
+ ret = -1;
}
- ret = pthread_mutex_unlock(&__urcu_compat_futex_lock);
- assert(!ret);
- return gret;
+end:
+ return ret;
}
/*
* _ASYNC SIGNAL-SAFE_.
* For now, timeout, uaddr2 and val3 are unused.
* Waiter will busy-loop trying to read the condition.
+ * It is OK to use compat_futex_async() on a futex address on which
+ * futex() WAKE operations are also performed.
*/
int compat_futex_async(int32_t *uaddr, int op, int32_t val,
const struct timespec *timeout, int32_t *uaddr2, int32_t val3)
{
+ int ret = 0;
+
/*
* Check if NULL. Don't let users expect that they are taken into
- * account.
+ * account.
*/
assert(!timeout);
assert(!uaddr2);
switch (op) {
case FUTEX_WAIT:
- while (CMM_LOAD_SHARED(*uaddr) == val)
- poll(NULL, 0, 10);
+ while (CMM_LOAD_SHARED(*uaddr) == val) {
+ if (poll(NULL, 0, 10) < 0) {
+ ret = -1;
+ /* Keep poll errno. Caller handles EINTR. */
+ goto end;
+ }
+ }
break;
case FUTEX_WAKE:
break;
default:
- return -EINVAL;
+ errno = EINVAL;
+ ret = -1;
}
- return 0;
+end:
+ return ret;
}