]> err.no Git - varnish/commitdiff
Add a check to ensure that the event handler is never called by foreign
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 29 Jan 2008 08:14:49 +0000 (08:14 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 29 Jan 2008 08:14:49 +0000 (08:14 +0000)
threads.

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

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2393 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/mgt_event.c

index 5aee213acb76b977060a8cf9a86f6e7843db27bd..92956f36d45995cc466f57490374e1b522192c9b 100644 (file)
@@ -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 @@ struct evbase {
        unsigned char           compact_pfd;
        unsigned char           disturbed;
        unsigned                psig;
+       pthread_t               thread;
 };
 
 /*--------------------------------------------------------------------*/
@@ -175,6 +177,7 @@ ev_new_base(void)
        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 @@ void
 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 @@ ev_add(struct evbase *evb, struct ev *e)
        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 @@ ev_del(struct evbase *evb, struct ev *e)
        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 @@ ev_schedule(struct evbase *evb)
        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 @@ ev_schedule_one(struct evbase *evb)
        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);