Mailing List Archive

[master] e622ed38c Use Lck_CondWait() and Lck_CondWaitTimeout() instead of Lck_CondWaitUntil()
commit e622ed38ca0fa8fd2b6223a52de17f580bb8dc3f
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date: Tue Oct 12 15:31:32 2021 +0000

Use Lck_CondWait() and Lck_CondWaitTimeout() instead of Lck_CondWaitUntil()

diff --git a/bin/varnishd/cache/cache_ban_lurker.c b/bin/varnishd/cache/cache_ban_lurker.c
index c7c41e077..ab5280e88 100644
--- a/bin/varnishd/cache/cache_ban_lurker.c
+++ b/bin/varnishd/cache/cache_ban_lurker.c
@@ -413,7 +413,6 @@ void * v_matchproto_(bgthread_t)
ban_lurker(struct worker *wrk, void *priv)
{
struct vsl_log vsl;
- vtim_real d;
vtim_dur dt;
unsigned gen = ban_generation + 1;

@@ -426,11 +425,11 @@ ban_lurker(struct worker *wrk, void *priv)
dt = ban_lurker_work(wrk, &vsl);
if (DO_DEBUG(DBG_LURKER))
VSLb(&vsl, SLT_Debug, "lurker: sleep = %lf", dt);
- d = VTIM_real() + dt;
Lck_Lock(&ban_mtx);
if (gen == ban_generation) {
Pool_Sumstat(wrk);
- (void)Lck_CondWaitUntil(&ban_lurker_cond, &ban_mtx, d);
+ (void)Lck_CondWaitTimeout(
+ &ban_lurker_cond, &ban_mtx, dt);
ban_batch = 0;
}
gen = ban_generation;
diff --git a/bin/varnishd/cache/cache_conn_pool.c b/bin/varnishd/cache/cache_conn_pool.c
index a1ec971ea..2a2a76ca8 100644
--- a/bin/varnishd/cache/cache_conn_pool.c
+++ b/bin/varnishd/cache/cache_conn_pool.c
@@ -488,7 +488,7 @@ VCP_Get(struct conn_pool *cp, vtim_dur tmo, struct worker *wrk,
*/

int
-VCP_Wait(struct worker *wrk, struct pfd *pfd, vtim_real tmo)
+VCP_Wait(struct worker *wrk, struct pfd *pfd, vtim_real when)
{
struct conn_pool *cp;
int r;
@@ -500,7 +500,7 @@ VCP_Wait(struct worker *wrk, struct pfd *pfd, vtim_real tmo)
assert(pfd->cond == &wrk->cond);
Lck_Lock(&cp->mtx);
while (pfd->state == PFD_STATE_STOLEN) {
- r = Lck_CondWaitUntil(&wrk->cond, &cp->mtx, tmo);
+ r = Lck_CondWaitUntil(&wrk->cond, &cp->mtx, when);
if (r != 0) {
if (r == EINTR)
continue;
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index f712b693e..c6fc3b0b6 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -202,8 +202,7 @@ ved_include(struct req *preq, const char *src, const char *host,
assert(s == REQ_FSM_DISEMBARK);
Lck_Lock(&sp->mtx);
if (!ecx->woken)
- (void)Lck_CondWaitUntil(
- &ecx->preq->wrk->cond, &sp->mtx, 0);
+ (void)Lck_CondWait(&ecx->preq->wrk->cond, &sp->mtx);
Lck_Unlock(&sp->mtx);
AZ(req->wrk);
}
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index e5cd2af28..24785b567 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -257,7 +257,7 @@ ObjWaitExtend(const struct worker *wrk, const struct objcore *oc, uint64_t l)
assert(l <= rv || oc->boc->state == BOS_FAILED);
if (rv > l || oc->boc->state >= BOS_FINISHED)
break;
- (void)Lck_CondWaitUntil(&oc->boc->cond, &oc->boc->mtx, 0);
+ (void)Lck_CondWait(&oc->boc->cond, &oc->boc->mtx);
}
rv = oc->boc->len_so_far;
Lck_Unlock(&oc->boc->mtx);
@@ -307,7 +307,7 @@ ObjWaitState(const struct objcore *oc, enum boc_state_e want)
while (1) {
if (oc->boc->state >= want)
break;
- (void)Lck_CondWaitUntil(&oc->boc->cond, &oc->boc->mtx, 0);
+ (void)Lck_CondWait(&oc->boc->cond, &oc->boc->mtx);
}
Lck_Unlock(&oc->boc->mtx);
}
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 02be15c81..3ef669de8 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -440,7 +440,8 @@ Pool_Work_Thread(struct pool *pp, struct worker *wrk)
tmo = now + 1.;
else
tmo = now + 60.;
- (void)Lck_CondWaitUntil(&wrk->cond, &pp->mtx, tmo);
+ (void)Lck_CondWaitUntil(
+ &wrk->cond, &pp->mtx, tmo);
if (wrk->task->func != NULL) {
/* We have been handed a new task */
tpx = *wrk->task;
@@ -697,14 +698,14 @@ pool_herder(void *priv)
if (pp->lqueue == 0) {
if (DO_DEBUG(DBG_VTC_MODE))
delay = 0.5;
- r = Lck_CondWaitUntil(&pp->herder_cond, &pp->mtx,
- VTIM_real() + delay);
+ r = Lck_CondWaitTimeout(
+ &pp->herder_cond, &pp->mtx, delay);
} else if (pp->nthr >= cache_param->wthread_max) {
/* XXX: unsafe counters */
if (r != ETIMEDOUT)
VSC_C_main->threads_limited++;
- r = Lck_CondWaitUntil(&pp->herder_cond, &pp->mtx,
- VTIM_real() + 1.0);
+ r = Lck_CondWaitTimeout(
+ &pp->herder_cond, &pp->mtx, 1.0);
}
Lck_Unlock(&pp->mtx);
}
diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index 4d9dc37b1..572275392 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -1038,8 +1038,8 @@ h2_vfp_body(struct vfp_ctx *vc, struct vfp_entry *vfe, void *ptr, ssize_t *lp)
if (retval != VFP_OK || l > 0)
break;

- i = Lck_CondWaitUntil(r2->cond, &h2->sess->mtx,
- VTIM_real() + SESS_TMO(h2->sess, timeout_idle));
+ i = Lck_CondWaitTimeout(r2->cond, &h2->sess->mtx,
+ SESS_TMO(h2->sess, timeout_idle));
if (i == ETIMEDOUT) {
retval = VFP_ERROR;
break;
diff --git a/bin/varnishd/http2/cache_http2_send.c b/bin/varnishd/http2/cache_http2_send.c
index a1439c0a5..84c6e2c93 100644
--- a/bin/varnishd/http2/cache_http2_send.c
+++ b/bin/varnishd/http2/cache_http2_send.c
@@ -46,7 +46,8 @@
static int
h2_cond_wait(pthread_cond_t *cond, struct h2_sess *h2, struct h2_req *r2)
{
- vtim_real now, when = 0.;
+ vtim_dur tmo = 0.;
+ vtim_real now;
int r;

AN(cond);
@@ -55,11 +56,10 @@ h2_cond_wait(pthread_cond_t *cond, struct h2_sess *h2, struct h2_req *r2)

Lck_AssertHeld(&h2->sess->mtx);

- now = VTIM_real();
if (cache_param->idle_send_timeout > 0.)
- when = now + cache_param->idle_send_timeout;
+ tmo = cache_param->idle_send_timeout;

- r = Lck_CondWaitUntil(cond, &h2->sess->mtx, when);
+ r = Lck_CondWaitTimeout(cond, &h2->sess->mtx, tmo);
assert(r == 0 || r == ETIMEDOUT);

now = VTIM_real();
@@ -100,7 +100,7 @@ h2_send_get_locked(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
r2->wrk = wrk;
VTAILQ_INSERT_TAIL(&h2->txqueue, r2, tx_list);
while (!H2_SEND_HELD(h2, r2))
- AZ(Lck_CondWaitUntil(&wrk->cond, &h2->sess->mtx, 0));
+ AZ(Lck_CondWait(&wrk->cond, &h2->sess->mtx));
r2->wrk = NULL;
}

diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c
index 899f2ec56..889441a4c 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -429,7 +429,7 @@ h2_new_session(struct worker *wrk, void *arg)
VTAILQ_FOREACH(r2, &h2->streams, list)
VSLb(h2->vsl, SLT_Debug, "ST %u %d",
r2->stream, r2->state);
- (void)Lck_CondWaitUntil(h2->cond, &h2->sess->mtx, VTIM_real() + .1);
+ (void)Lck_CondWaitTimeout(h2->cond, &h2->sess->mtx, .1);
Lck_Unlock(&h2->sess->mtx);
}
h2->cond = NULL;
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit