/*
- * $Id: event.cc,v 1.36 2003/02/21 22:50:08 robertc Exp $
+ * $Id: event.cc,v 1.37 2003/05/18 00:34:49 robertc Exp $
*
* DEBUG: section 41 Event Processing
* AUTHOR: Henrik Nordstrom
struct ev_entry *next;
int weight;
int id;
+ bool cbdata;
};
static struct ev_entry *tasks = NULL;
static const char *last_event_ran = NULL;
void
-eventAdd(const char *name, EVH * func, void *arg, double when, int weight)
+eventAdd(const char *name, EVH * func, void *arg, double when, int weight, bool cbdata)
{
struct ev_entry *event = (ev_entry *)memAllocate(MEM_EVENT);
struct ev_entry **E;
event->func = func;
- event->arg = cbdataReference(arg);
+ event->arg = cbdata ? cbdataReference(arg) : arg;
event->name = name;
event->when = current_dtime + when;
event->weight = weight;
event->id = run_id;
+ event->cbdata = cbdata;
debug(41, 7) ("eventAdd: Adding '%s', in %f seconds\n", name, when);
/* Insert after the last event with the same or earlier time */
*E = event->next;
- cbdataReferenceDone(event->arg);
+ if (event->cbdata)
+ cbdataReferenceDone(event->arg);
memFree(event, MEM_EVENT);
event->func = NULL;
- if (cbdataReferenceValidDone(event->arg, &cbdata)) {
+ if (!event->cbdata || cbdataReferenceValidDone(event->arg, &cbdata)) {
weight += event->weight;
/* XXX assumes ->name is static memory! */
last_event_ran = event->name;
while (e != NULL) {
storeAppendPrintf(sentry, "%s\t%f seconds\t%d\t%s\n",
e->name, e->when - current_dtime, e->weight,
- e->arg ? cbdataReferenceValid(e->arg) ? "yes" : "no" : "N/A");
+ (e->arg && e->cbdata) ? cbdataReferenceValid(e->arg) ? "yes" : "no" : "N/A");
e = e->next;
}
}
while ((event = tasks)) {
tasks = event->next;
- cbdataReferenceDone(event->arg);
+
+ if (event->cbdata)
+ cbdataReferenceDone(event->arg);
+
memFree(event, MEM_EVENT);
}
/*
- * $Id: protos.h,v 1.477 2003/04/24 06:35:09 hno Exp $
+ * $Id: protos.h,v 1.478 2003/05/18 00:34:50 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
SQUIDCEXTERN void idnsPTRLookup(const struct in_addr, IDNSCB *, void *);
-SQUIDCEXTERN void eventAdd(const char *name, EVH * func, void *arg, double when, int);
+SQUIDCEXTERN void eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata=true);
SQUIDCEXTERN void eventAddIsh(const char *name, EVH * func, void *arg, double delta_ish, int);
SQUIDCEXTERN void eventRun(void);
SQUIDCEXTERN int eventNextTime(void);