Mailing List Archive

[master] a2a00988d (Re)introduce Lck_CondWait() which waits forever and …Timeout which does not.
commit a2a00988d4286421213824d772125303171d9dca
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date: Tue Oct 12 14:59:59 2021 +0000

(Re)introduce Lck_CondWait() which waits forever and …Timeout which does not.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index f8e3514f2..e9803d8d1 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -690,7 +690,9 @@ extern pthread_mutexattr_t mtxattr_errorcheck;

/* public interface: */
void Lck_Delete(struct lock *lck);
-int Lck_CondWaitUntil(pthread_cond_t *cond, struct lock *lck, vtim_real);
+int Lck_CondWaitUntil(pthread_cond_t *, struct lock *, vtim_real when);
+int Lck_CondWait(pthread_cond_t *, struct lock *);
+int Lck_CondWaitTimeout(pthread_cond_t *, struct lock *, vtim_dur timeout);

#define Lck_New(a, b) Lck__New(a, b, #b)
#define Lck_Lock(a) Lck__Lock(a, __func__, __LINE__)
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index a0aaaa907..a41b9a93e 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -42,9 +42,7 @@
#include <stdlib.h>
#include <stdio.h>

-#if defined (__APPLE__)
-# include "vtim.h"
-#endif
+#include "vtim.h"

#include "VSC_lck.h"

@@ -207,6 +205,24 @@ Lck__Owned(const struct lock *lck)
return (pthread_equal(ilck->owner, pthread_self()));
}

+int v_matchproto_()
+Lck_CondWait(pthread_cond_t *cond, struct lock *lck)
+{
+ return (Lck_CondWaitUntil(cond, lck, 0));
+}
+
+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));
+}
+
int v_matchproto_()
Lck_CondWaitUntil(pthread_cond_t *cond, struct lock *lck, vtim_real when)
{
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit