PERFORCE change 120767 for review
Fredrik Lindberg
fli at FreeBSD.org
Sat Jun 2 11:56:42 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=120767
Change 120767 by fli at fli_genesis on 2007/06/02 11:56:33
- Add debugging macros.
- No need to hold read lock during event handle execution.
- Style fixes.
Affected files ...
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/event.c#2 edit
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/event.h#2 edit
Differences ...
==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/event.c#2 (text+ko) ====
@@ -24,10 +24,11 @@
*
*/
-#include <stdlib.h>
-#include <stdio.h>
#include <sys/types.h>
#include <sys/event.h>
+
+#include <stdio.h>
+#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <strings.h>
@@ -36,6 +37,7 @@
#include "event.h"
#include "wqueue.h"
#include "log.h"
+#include "debug.h"
static int remove_event(struct eventlist *, struct event *, ev_arg *);
static int event_engine(wq_arg);
@@ -76,6 +78,7 @@
#ifdef HAVE_PTHREAD
pthread_mutex_init(&evl->evl_mtx, NULL);
#endif
+ MDNS_INIT_SET(evl, evl_magic);
return (evl);
}
@@ -91,6 +94,7 @@
struct event *ev;
int empty;
+ MDNS_INIT_ASSERT(evl, evl_magic);
EVL_LOCK(evl);
while (!TAILQ_EMPTY(&evl->evl_events)) {
ev = TAILQ_FIRST(&evl->evl_events);
@@ -107,6 +111,7 @@
#ifdef HAVE_PTHREAD
pthread_mutex_destroy(&evl->evl_mtx);
#endif
+ MDNS_INIT_UNSET(evl, evl_magic);
free(evl);
}
else {
@@ -130,9 +135,8 @@
int ret;
ev = (struct event *)arg.ptr;
+ MDNS_INIT_ASSERT(ev, ev_magic);
- /* Grab a read-lock during the time we execute the handler */
- EV_RLOCK(ev);
switch (ev->ev_type) {
case EVENT_TYPE_IO:
ret = ev->ev_cb.ev_handler.io(&ev->ev_data.io, ev->ev_handler_arg);
@@ -145,15 +149,15 @@
break;
}
- /* "Upgrade" to write-lock */
- EV_UNLOCK(ev);
EV_WLOCK(ev);
ev->ev_refcnt--;
if (ev->ev_flags & EVENT_FLAG_DYING) {
evl = ev->ev_evl;
remove_event(evl, ev, NULL);
}
- EV_UNLOCK(ev);
+ else {
+ EV_UNLOCK(ev);
+ }
return (0);
}
@@ -174,6 +178,7 @@
wq_arg wa;
struct kevent kev;
+ MDNS_INIT_ASSERT(evl, evl_magic);
EVL_LOCK(evl);
kq = evl->evl_kq;
EVL_UNLOCK(evl);
@@ -219,14 +224,17 @@
}
/* Exclusive event already in progress */
- if (ev->ev_flags & EVENT_FLAG_EX && ev->ev_refcnt > 0) {
+ if ((ev->ev_flags & EVENT_FLAG_EX) && ev->ev_refcnt > 0) {
+ dprintf(DEBUG_EVENT,
+ "Exclusive event already in progress ev=%x", ev);
EV_UNLOCK(ev);
continue;
}
ev->ev_refcnt++;
EV_UNLOCK(ev);
- dprintf(DEBUG_EVENT, "Event fired, dispatched to queue=%x, ev=%x", wq, ev);
+ dprintf(DEBUG_EVENT, "Event fired, dispatched to queue=%x, ev=%x",
+ wq, ev);
wa.ptr = ev;
#ifdef HAVE_PTHREAD
error = wq_enqueue(wq, event_engine, &wa);
@@ -250,6 +258,7 @@
{
pid_t self;
+ MDNS_INIT_ASSERT(evl, evl_magic);
EVL_LOCK(evl);
dprintf(DEBUG_EVENT, "Event exit called");
evl->evl_flags |= EVL_FLAG_DYING;
@@ -282,6 +291,7 @@
ev_arg ev_arg_init;
struct kevent kev;
+ MDNS_INIT_ASSERT(evl, evl_magic);
ev = malloc(sizeof(struct event));
if (ev == NULL)
return (-1);
@@ -364,9 +374,10 @@
TAILQ_INSERT_TAIL(&evl->evl_events, ev, ev_evlist);
EVL_UNLOCK(evl);
}
+ MDNS_INIT_SET(ev, ev_magic);
- dprintf(DEBUG_EVENT, "Event added type=%d, ev=%x, handler=%x",
- type, ev, handler);
+ dprintf(DEBUG_EVENT, "Event added type=%d, id=%d, ev=%x, handler=%x",
+ type, ev->ev_id, ev, handler);
return (ev->ev_id);
}
@@ -384,8 +395,7 @@
{
struct event *ev = NULL;
- dprintf(DEBUG_EVENT, "Removing event ev=%x", ev);
-
+ MDNS_INIT_ASSERT(evl, evl_magic);
EVL_LOCK(evl);
TAILQ_FOREACH(ev, &evl->evl_events, ev_evlist) {
if (ev->ev_id == id)
@@ -397,12 +407,13 @@
return (-1);
}
EV_WLOCK(ev);
+ dprintf(DEBUG_EVENT, "Removing event ev=%x", ev);
if (remove_event(evl, ev, arg) == 1) {
EV_UNLOCK(ev);
}
- return (ev->ev_id);
+ return (0);
}
/*
@@ -420,6 +431,9 @@
ev_arg ev_arg_init;
struct kevent kev;
+ MDNS_INIT_ASSERT(evl, evl_magic);
+ MDNS_INIT_ASSERT(ev, ev_magic);
+
if (ev->ev_refcnt > 0) {
dprintf(DEBUG_EVENT, "Event busy ev=%x, refcnt=%d", ev, ev->ev_refcnt);
ev->ev_flags |= EVENT_FLAG_DYING;
@@ -468,6 +482,7 @@
kev.flags |= EV_DELETE | EV_CLEAR;
ret = kevent(evl->evl_kq, &kev, 1, NULL, 0, NULL);
+ MDNS_INIT_UNSET(ev, ev_magic);
free(ev);
dprintf(DEBUG_EVENT, "Event removed ev=%x", ev);
==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/event.h#2 (text+ko) ====
@@ -31,6 +31,7 @@
#include <sys/queue.h>
#include "wqueue.h"
+#include "debug.h"
/*
* Holds event id and backpointer to event list, included
@@ -97,6 +98,7 @@
*/
struct event;
struct eventlist {
+ MAGIC(evl_magic);
TAILQ_HEAD(, event) evl_events; /* list of events */
#ifdef HAVE_PTHREAD
pthread_mutex_t evl_mtx;
@@ -111,6 +113,7 @@
* Internal event structure, represents an event
*/
struct event {
+ MAGIC(ev_magic);
TAILQ_ENTRY(event) ev_evlist; /* global event list */
struct eventlist *ev_evl; /* back-pointer to list */
#ifdef HAVE_PTHREAD
More information about the p4-projects
mailing list