- Make ng_timeout() to use callout() interface instead of timeout().

- Remove callout-hacking from ng_untimeout().

Approved by:	julian (mentor)
MFC after:	1 month
This commit is contained in:
Gleb Smirnoff 2004-11-02 21:24:30 +00:00
parent 32672ba88d
commit 30bef41b8a
3 changed files with 28 additions and 30 deletions

View File

@ -1074,10 +1074,11 @@ int ng_rmtype(struct ng_type *tp);
int ng_snd_item(item_p item, int queue);
int ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn,
void *arg1, int arg2);
int ng_untimeout(struct callout_handle handle, node_p node);
struct callout_handle
ng_timeout(node_p node, hook_p hook, int ticks,
int ng_untimeout(struct callout *c, node_p node);
int ng_timeout(struct callout *c, node_p node, hook_p hook, int ticks,
ng_item_fn *fn, void * arg1, int arg2);
/* We should mark callout mpsafe as soon as we mark netgraph ISR mpsafe */
#define ng_callout_init(c) callout_init(c, 0)
/*
* prototypes the user should DEFINITELY not use directly

View File

@ -3595,17 +3595,15 @@ ng_timeout_trapoline(void *arg)
}
struct callout_handle
ng_timeout(node_p node, hook_p hook, int ticks,
int
ng_timeout(struct callout *c, node_p node, hook_p hook, int ticks,
ng_item_fn *fn, void * arg1, int arg2)
{
item_p item;
if ((item = ng_getqblk()) == NULL) {
struct callout_handle handle;
handle.callout = NULL;
return (handle);
}
if ((item = ng_getqblk()) == NULL)
return (ENOMEM);
item->el_flags = NGQF_FN | NGQF_WRITER;
NG_NODE_REF(node); /* and one for the item */
NGI_SET_NODE(item, node);
@ -3616,33 +3614,33 @@ ng_timeout(node_p node, hook_p hook, int ticks,
NGI_FN(item) = fn;
NGI_ARG1(item) = arg1;
NGI_ARG2(item) = arg2;
return (timeout(&ng_timeout_trapoline, item, ticks));
callout_reset(c, ticks, &ng_timeout_trapoline, item);
return (0);
}
/* A special modified version of untimeout() */
int
ng_untimeout(struct callout_handle handle, node_p node)
ng_untimeout(struct callout *c, node_p node)
{
item_p item;
int rval;
if (handle.callout == NULL)
if (c == NULL)
return (0);
mtx_lock_spin(&callout_lock);
item = handle.callout->c_arg; /* should be an official way to do this */
if ((handle.callout->c_func == &ng_timeout_trapoline) &&
(NGI_NODE(item) == node) &&
(callout_stop(handle.callout))) {
rval = callout_drain(c);
item = c->c_arg;
/* Do an extra check */
if ((c->c_func == &ng_timeout_trapoline) &&
(NGI_NODE(item) == node)) {
/*
* We successfully removed it from the queue before it ran
* So now we need to unreference everything that was
* given extra references. (NG_FREE_ITEM does this).
*/
mtx_unlock_spin(&callout_lock);
NG_FREE_ITEM(item);
return (1);
}
mtx_unlock_spin(&callout_lock);
return (0);
return (rval);
}
/*

View File

@ -87,7 +87,7 @@ struct privdata {
struct ng_source_stats stats;
struct ifqueue snd_queue; /* packets to send */
struct ifnet *output_ifp;
struct callout_handle intr_ch;
struct callout intr_ch;
u_int64_t packets; /* packets to send */
u_int32_t queueOctets;
};
@ -219,8 +219,8 @@ ng_source_constructor(node_p node)
NG_NODE_SET_PRIVATE(node, sc);
sc->node = node;
sc->snd_queue.ifq_maxlen = 2048; /* XXX not checked */
callout_handle_init(&sc->intr_ch); /* XXX fix.. will
cause problems. */
ng_callout_init(&sc->intr_ch);
return (0);
}
@ -331,7 +331,7 @@ ng_source_rcvmsg(node_p node, item_p item, hook_p lasthook)
timevalclear(&sc->stats.elapsedTime);
timevalclear(&sc->stats.endTime);
getmicrotime(&sc->stats.startTime);
sc->intr_ch = ng_timeout(node, NULL, 0,
ng_timeout(&sc->intr_ch, node, NULL, 0,
ng_source_intr, sc, 0);
}
break;
@ -359,7 +359,7 @@ ng_source_rcvmsg(node_p node, item_p item, hook_p lasthook)
timevalclear(&sc->stats.elapsedTime);
timevalclear(&sc->stats.endTime);
getmicrotime(&sc->stats.startTime);
sc->intr_ch = ng_timeout(node, NULL, 0,
ng_timeout(&sc->intr_ch, node, NULL, 0,
ng_source_intr, sc, 0);
}
break;
@ -586,7 +586,7 @@ static void
ng_source_stop (sc_p sc)
{
if (sc->node->nd_flags & NG_SOURCE_ACTIVE) {
ng_untimeout(sc->intr_ch, sc->node);
ng_untimeout(&sc->intr_ch, sc->node);
sc->node->nd_flags &= ~NG_SOURCE_ACTIVE;
getmicrotime(&sc->stats.endTime);
sc->stats.elapsedTime = sc->stats.endTime;
@ -610,7 +610,6 @@ ng_source_intr(node_p node, hook_p hook, void *arg1, int arg2)
KASSERT(sc != NULL, ("%s: null node private", __func__));
callout_handle_init(&sc->intr_ch);
if (sc->packets == 0 || sc->output.hook == NULL
|| (sc->node->nd_flags & NG_SOURCE_ACTIVE) == 0) {
ng_source_stop(sc);
@ -627,7 +626,7 @@ ng_source_intr(node_p node, hook_p hook, void *arg1, int arg2)
if (sc->packets == 0)
ng_source_stop(sc);
else
sc->intr_ch = ng_timeout(node, NULL, NG_SOURCE_INTR_TICKS,
ng_timeout(&sc->intr_ch, node, NULL, NG_SOURCE_INTR_TICKS,
ng_source_intr, sc, 0);
}