Skip to content
Snippets Groups Projects
Commit 32be981c authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Konstantin Osipov
Browse files

Add and use fiber_cond_wait_deadline

Like fiber_cond_wait_timeout(), but waits for a deadline to pass.

Follow-up b4bf3fa0 ("applier: use fiber_cond instead of fiber_channel");
parent f33b6f8a
No related branches found
No related tags found
No related merge requests found
......@@ -702,13 +702,12 @@ static inline int
applier_wait_for_state(struct applier_on_state *trigger, double timeout)
{
struct applier *applier = trigger->applier;
double deadline = ev_monotonic_now(loop()) + timeout;
while (applier->state != APPLIER_OFF &&
applier->state != APPLIER_STOPPED &&
applier->state != trigger->desired_state) {
double wait_start = ev_monotonic_now(loop());
if (fiber_cond_wait_timeout(&trigger->wakeup, timeout) != 0)
if (fiber_cond_wait_deadline(&trigger->wakeup, deadline) != 0)
return -1; /* ER_TIMEOUT */
timeout -= ev_monotonic_now(loop()) - wait_start;
}
if (applier->state != trigger->desired_state) {
assert(applier->state == APPLIER_OFF ||
......
......@@ -148,13 +148,11 @@ vy_quota_release(struct vy_quota *q, size_t size)
static inline int
vy_quota_use(struct vy_quota *q, size_t size, double timeout)
{
double deadline = ev_monotonic_now(loop()) + timeout;
while (q->used + size > q->limit && timeout > 0) {
q->quota_exceeded_cb(q);
double wait_start = ev_monotonic_now(loop());
if (fiber_cond_wait_timeout(&q->cond, timeout) != 0)
if (fiber_cond_wait_deadline(&q->cond, deadline) != 0)
break; /* timed out */
double wait_end = ev_monotonic_now(loop());
timeout -= (wait_end - wait_start);
}
if (q->used + size > q->limit)
return -1;
......
......@@ -116,3 +116,10 @@ fiber_cond_wait(struct fiber_cond *c)
{
return fiber_cond_wait_timeout(c, TIMEOUT_INFINITY);
}
int
fiber_cond_wait_deadline(struct fiber_cond *c, double deadline)
{
double timeout = deadline - ev_monotonic_now(loop());
return fiber_cond_wait_timeout(c, timeout);
}
......@@ -128,6 +128,15 @@ fiber_cond_wait(struct fiber_cond *cond);
/** \endcond public */
/**
* Wait until the given condition variable is signaled or the
* deadline passed. The deadline is specified as absolute time
* in seconds since system start (i.e. monotonic clock).
* @see fiber_cond_wait_timeout()
*/
int
fiber_cond_wait_deadline(struct fiber_cond *cond, double deadline);
#if defined(__cplusplus)
} /* extern "C" */
#endif /* defined(__cplusplus) */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment