}
+boolean
+lp_fence_timedwait(struct lp_fence *f, uint64_t timeout)
+{
+ struct timespec ts;
+ int ret;
+
+ timespec_get(&ts, TIME_UTC);
+
+ ts.tv_nsec += timeout % 1000000000L;
+ ts.tv_sec += timeout / 1000000000L;
+ if (ts.tv_nsec >= 1000000000L) {
+ ts.tv_sec++;
+ ts.tv_nsec -= 1000000000L;
+ }
+
+ if (LP_DEBUG & DEBUG_FENCE)
+ debug_printf("%s %d\n", __FUNCTION__, f->id);
+
+ mtx_lock(&f->mutex);
+ assert(f->issued);
+ while (f->count < f->rank) {
+ ret = cnd_timedwait(&f->signalled, &f->mutex, &ts);
+ if (ret != thrd_success)
+ break;
+ }
+ const boolean result = (f->count >= f->rank);
+ mtx_unlock(&f->mutex);
+ return result;
+}