Skip to content

Commit

Permalink
lck: Apply "never" timeouts to cond waits
Browse files Browse the repository at this point in the history
The vtim_real in Lck_CondWaitUntil() is not meant to be INFINITY, and it
should only apply to the vtim_dur passed to Lck_CondWaitTimeout(). In
practice it does since the latter calls the former. It could be enforced
by extracting a static function from Lck_CondWaitUntil().

This accommodates a few timeout parameters that are used for cond waits.
  • Loading branch information
dridi committed Mar 5, 2024
1 parent fe3f7e9 commit a26123f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions bin/varnishd/cache/cache_lck.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,20 @@ Lck__Owned(const struct lock *lck)
int v_matchproto_()
Lck_CondWait(pthread_cond_t *cond, struct lock *lck)
{
return (Lck_CondWaitUntil(cond, lck, 0));
return (Lck_CondWaitUntil(cond, lck, INFINITY));
}

int v_matchproto_()
Lck_CondWaitTimeout(pthread_cond_t *cond, struct lock *lck, vtim_dur timeout)
{
assert(timeout >= 0);
assert(timeout < 3600);

if (timeout == 0)
return (Lck_CondWaitUntil(cond, lck, 0));
else
return (Lck_CondWaitUntil(cond, lck, VTIM_real() + timeout));
if (isinf(timeout))
return (Lck_CondWaitUntil(cond, lck, INFINITY));

assert(timeout >= 0);
assert(timeout <= 3600);
timeout = vmax(timeout, 1e-3);
return (Lck_CondWaitUntil(cond, lck, VTIM_real() + timeout));
}

int v_matchproto_()
Expand All @@ -235,7 +236,7 @@ Lck_CondWaitUntil(pthread_cond_t *cond, struct lock *lck, vtim_real when)
AN(ilck->held);
assert(pthread_equal(ilck->owner, pthread_self()));
ilck->held = 0;
if (when == 0) {
if (isinf(when)) {
errno = pthread_cond_wait(cond, &ilck->mtx);
AZ(errno);
} else {
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_wrk.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ Pool_Work_Thread(struct pool *pp, struct worker *wrk)
* chance to push stats. */
tmo = now + 1.;
else if (wrk->wpriv->vcl == NULL)
tmo = 0;
tmo = INFINITY;
else if (DO_DEBUG(DBG_VTC_MODE))
tmo = now + 1.;
else
Expand Down

0 comments on commit a26123f

Please sign in to comment.