[master] c960cd1 sort functions into Wait_ and Waited_

Poul-Henning Kamp phk at FreeBSD.org
Thu May 21 18:48:51 CEST 2015


commit c960cd16387c21ca4fe4745074a137d1eb6650e6
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 19 09:31:19 2015 +0000

    sort functions into Wait_ and Waited_

diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index c65adcd..c1a03fa 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -76,91 +76,6 @@ wait_poker_thread(void *arg)
 	NEEDLESS_RETURN(NULL);
 }
 
-const char *
-Waiter_GetName(void)
-{
-
-	if (waiter != NULL)
-		return (waiter->name);
-	else
-		return ("no_waiter");
-}
-
-struct waiter *
-Waiter_New(waiter_handle_f *func, volatile double *tmo)
-{
-	struct waiter *w;
-
-	AN(waiter);
-	AN(waiter->name);
-	AN(waiter->init);
-
-	w = calloc(1, sizeof (struct waiter) + waiter->size);
-	AN(w);
-	INIT_OBJ(w, WAITER_MAGIC);
-	w->priv = (void*)(w + 1);
-	w->impl = waiter;
-	w->func = func;
-	w->tmo = tmo;
-	w->pipes[0] = w->pipes[1] = -1;
-	VTAILQ_INIT(&w->waithead);
-
-	waiter->init(w);
-	AN(w->impl->pass || w->pipes[1] >= 0);
-
-	Lck_Lock(&wait_mtx);
-	VTAILQ_INSERT_TAIL(&waiters, w, list);
-	nwaiters++;
-
-	/* We assume all waiters either use pipes or don't use pipes */
-	if (w->pipes[1] >= 0 && nwaiters == 1)
-		AZ(pthread_create(&wait_thr, NULL, wait_poker_thread, NULL));
-	Lck_Unlock(&wait_mtx);
-	return (w);
-}
-
-void
-Waiter_Destroy(struct waiter **wp)
-{
-	struct waiter *w;
-	struct waited *wx = NULL;
-	int written;
-	double now;
-
-	AN(wp);
-	w = *wp;
-	*wp = NULL;
-	CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
-
-	Lck_Lock(&wait_mtx);
-	VTAILQ_REMOVE(&waiters, w, list);
-	w->dismantle = 1;
-	Lck_Unlock(&wait_mtx);
-
-	if (w->pipes[1] >= 0) {
-		while (1) {
-			written = write(w->pipes[1], &wx, sizeof wx);
-			if (written == sizeof wx)
-				break;
-			(void)usleep(10000);
-		}
-	}
-	AN(w->impl->fini);
-	w->impl->fini(w);
-	now = VTIM_real();
-	while (1) {
-		wx = VTAILQ_FIRST(&w->waithead);
-		if (wx == NULL)
-			break;
-		VTAILQ_REMOVE(&w->waithead, wx, list);
-		if (wx == w->pipe_w)
-			FREE_OBJ(wx);
-		else
-			w->func(wx, WAITER_CLOSE, now);
-	}
-	FREE_OBJ(w);
-}
-
 void
 Wait_UsePipe(struct waiter *w)
 {
@@ -291,6 +206,93 @@ Wait_Handle(struct waiter *w, struct waited *wp, enum wait_event ev, double now)
 	wait_updidle(w, now);
 }
 
+/**********************************************************************/
+
+const char *
+Waiter_GetName(void)
+{
+
+	if (waiter != NULL)
+		return (waiter->name);
+	else
+		return ("no_waiter");
+}
+
+struct waiter *
+Waiter_New(waiter_handle_f *func, volatile double *tmo)
+{
+	struct waiter *w;
+
+	AN(waiter);
+	AN(waiter->name);
+	AN(waiter->init);
+
+	w = calloc(1, sizeof (struct waiter) + waiter->size);
+	AN(w);
+	INIT_OBJ(w, WAITER_MAGIC);
+	w->priv = (void*)(w + 1);
+	w->impl = waiter;
+	w->func = func;
+	w->tmo = tmo;
+	w->pipes[0] = w->pipes[1] = -1;
+	VTAILQ_INIT(&w->waithead);
+
+	waiter->init(w);
+	AN(w->impl->pass || w->pipes[1] >= 0);
+
+	Lck_Lock(&wait_mtx);
+	VTAILQ_INSERT_TAIL(&waiters, w, list);
+	nwaiters++;
+
+	/* We assume all waiters either use pipes or don't use pipes */
+	if (w->pipes[1] >= 0 && nwaiters == 1)
+		AZ(pthread_create(&wait_thr, NULL, wait_poker_thread, NULL));
+	Lck_Unlock(&wait_mtx);
+	return (w);
+}
+
+void
+Waiter_Destroy(struct waiter **wp)
+{
+	struct waiter *w;
+	struct waited *wx = NULL;
+	int written;
+	double now;
+
+	AN(wp);
+	w = *wp;
+	*wp = NULL;
+	CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
+
+	Lck_Lock(&wait_mtx);
+	VTAILQ_REMOVE(&waiters, w, list);
+	w->dismantle = 1;
+	Lck_Unlock(&wait_mtx);
+
+	if (w->pipes[1] >= 0) {
+		while (1) {
+			written = write(w->pipes[1], &wx, sizeof wx);
+			if (written == sizeof wx)
+				break;
+			(void)usleep(10000);
+		}
+	}
+	AN(w->impl->fini);
+	w->impl->fini(w);
+	now = VTIM_real();
+	while (1) {
+		wx = VTAILQ_FIRST(&w->waithead);
+		if (wx == NULL)
+			break;
+		VTAILQ_REMOVE(&w->waithead, wx, list);
+		if (wx == w->pipe_w)
+			FREE_OBJ(wx);
+		else
+			w->func(wx, WAITER_CLOSE, now);
+	}
+	FREE_OBJ(w);
+}
+
 void
 Waiter_Init(void)
 {



More information about the varnish-commit mailing list