r2393 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Jan 29 09:14:50 CET 2008


Author: phk
Date: 2008-01-29 09:14:49 +0100 (Tue, 29 Jan 2008)
New Revision: 2393

Modified:
   trunk/varnish-cache/bin/varnishd/mgt_event.c
Log:
Add a check to ensure that the event handler is never called by foreign
threads.

Inspired by, but not expected to have any effect on #199


Modified: trunk/varnish-cache/bin/varnishd/mgt_event.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_event.c	2008-01-28 10:28:24 UTC (rev 2392)
+++ trunk/varnish-cache/bin/varnishd/mgt_event.c	2008-01-29 08:14:49 UTC (rev 2393)
@@ -36,6 +36,7 @@
 #include <signal.h>
 #include <string.h>
 #include <stdlib.h>
+#include <pthread.h>
 
 #include "mgt.h"
 #include "mgt_event.h"
@@ -68,6 +69,7 @@
 	unsigned char		compact_pfd;
 	unsigned char		disturbed;
 	unsigned		psig;
+	pthread_t		thread;
 };
 
 /*--------------------------------------------------------------------*/
@@ -175,6 +177,7 @@
 	evb->magic = EVBASE_MAGIC;
 	VTAILQ_INIT(&evb->events);
 	evb->binheap = binheap_new(evb, ev_bh_cmp, ev_bh_update);
+	evb->thread = pthread_self();
 	return (evb);
 }
 
@@ -184,6 +187,7 @@
 ev_destroy_base(struct evbase *evb)
 {
 	CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC);
+	assert(evb->thread == pthread_self());
 	evb->magic = 0;
 	free(evb);
 }
@@ -215,6 +219,7 @@
 	assert(e->sig >= 0);
 	assert(e->timeout >= 0.0);
 	assert(e->fd < 0 || e->fd_flags);
+	assert(evb->thread == pthread_self());
 
 	if (e->sig > 0 && ev_get_sig(e->sig))
 		return (ENOMEM);
@@ -281,6 +286,7 @@
 	CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC);
 	CHECK_OBJ_NOTNULL(e, EV_MAGIC);
 	assert(evb == e->__evb);
+	assert(evb->thread == pthread_self());
 
 	if (e->__binheap_idx != 0)
 		binheap_delete(evb->binheap, e->__binheap_idx);
@@ -323,6 +329,7 @@
 	int i;
 
 	CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC);
+	assert(evb->thread == pthread_self());
 	do
 		i = ev_schedule_one(evb);
 	while (i == 1);
@@ -409,6 +416,7 @@
 	struct pollfd *pfd;
 
 	CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC);
+	assert(evb->thread == pthread_self());
 	e = binheap_root(evb->binheap);
 	if (e != NULL) {
 		CHECK_OBJ_NOTNULL(e, EV_MAGIC);




More information about the varnish-commit mailing list