Deleted Added
full compact
ng_base.c (137230) ng_base.c (138268)
1/*
2 * ng_base.c
3 *
4 * Copyright (c) 1996-1999 Whistle Communications, Inc.
5 * All rights reserved.
6 *
7 * Subject to the following obligations and disclaimer of warranty, use and
8 * redistribution of this software, in source or object code forms, with or

--- 22 unchanged lines hidden (view full) ---

31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
34 * OF SUCH DAMAGE.
35 *
36 * Authors: Julian Elischer <julian@freebsd.org>
37 * Archie Cobbs <archie@freebsd.org>
38 *
1/*
2 * ng_base.c
3 *
4 * Copyright (c) 1996-1999 Whistle Communications, Inc.
5 * All rights reserved.
6 *
7 * Subject to the following obligations and disclaimer of warranty, use and
8 * redistribution of this software, in source or object code forms, with or

--- 22 unchanged lines hidden (view full) ---

31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
34 * OF SUCH DAMAGE.
35 *
36 * Authors: Julian Elischer <julian@freebsd.org>
37 * Archie Cobbs <archie@freebsd.org>
38 *
39 * $FreeBSD: head/sys/netgraph/ng_base.c 137230 2004-11-04 21:30:18Z glebius $
39 * $FreeBSD: head/sys/netgraph/ng_base.c 138268 2004-12-01 11:56:32Z glebius $
40 * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $
41 */
42
43/*
44 * This file implements the base netgraph code.
45 */
46
47#include <sys/param.h>

--- 3534 unchanged lines hidden (view full) ---

3582 NGI_ARG2(item) = arg2;
3583 return(ng_snd_item(item, 0));
3584}
3585
3586/*
3587 * Official timeout routines for Netgraph nodes.
3588 */
3589static void
40 * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $
41 */
42
43/*
44 * This file implements the base netgraph code.
45 */
46
47#include <sys/param.h>

--- 3534 unchanged lines hidden (view full) ---

3582 NGI_ARG2(item) = arg2;
3583 return(ng_snd_item(item, 0));
3584}
3585
3586/*
3587 * Official timeout routines for Netgraph nodes.
3588 */
3589static void
3590ng_timeout_trapoline(void *arg)
3590ng_callout_trapoline(void *arg)
3591{
3592 item_p item = arg;
3593
3594 ng_snd_item(item, 0);
3595}
3596
3597
3598int
3591{
3592 item_p item = arg;
3593
3594 ng_snd_item(item, 0);
3595}
3596
3597
3598int
3599ng_timeout(struct callout *c, node_p node, hook_p hook, int ticks,
3599ng_callout(struct callout *c, node_p node, hook_p hook, int ticks,
3600 ng_item_fn *fn, void * arg1, int arg2)
3601{
3602 item_p item;
3603
3604 if ((item = ng_getqblk()) == NULL)
3605 return (ENOMEM);
3606
3607 item->el_flags = NGQF_FN | NGQF_WRITER;
3608 NG_NODE_REF(node); /* and one for the item */
3609 NGI_SET_NODE(item, node);
3610 if (hook) {
3611 NG_HOOK_REF(hook);
3612 NGI_SET_HOOK(item, hook);
3613 }
3614 NGI_FN(item) = fn;
3615 NGI_ARG1(item) = arg1;
3616 NGI_ARG2(item) = arg2;
3600 ng_item_fn *fn, void * arg1, int arg2)
3601{
3602 item_p item;
3603
3604 if ((item = ng_getqblk()) == NULL)
3605 return (ENOMEM);
3606
3607 item->el_flags = NGQF_FN | NGQF_WRITER;
3608 NG_NODE_REF(node); /* and one for the item */
3609 NGI_SET_NODE(item, node);
3610 if (hook) {
3611 NG_HOOK_REF(hook);
3612 NGI_SET_HOOK(item, hook);
3613 }
3614 NGI_FN(item) = fn;
3615 NGI_ARG1(item) = arg1;
3616 NGI_ARG2(item) = arg2;
3617 callout_reset(c, ticks, &ng_timeout_trapoline, item);
3617 callout_reset(c, ticks, &ng_callout_trapoline, item);
3618 return (0);
3619}
3620
3621/* A special modified version of untimeout() */
3622int
3618 return (0);
3619}
3620
3621/* A special modified version of untimeout() */
3622int
3623ng_untimeout(struct callout *c, node_p node)
3623ng_uncallout(struct callout *c, node_p node)
3624{
3625 item_p item;
3626 int rval;
3627 void *c_func;
3628
3629 if (c == NULL)
3630 return (0);
3631 /* there must be an official way to do this */
3632 mtx_lock_spin(&callout_lock);
3633 c_func = c->c_func;
3634 rval = callout_stop(c);
3635 mtx_unlock_spin(&callout_lock);
3636 item = c->c_arg;
3637 /* Do an extra check */
3624{
3625 item_p item;
3626 int rval;
3627 void *c_func;
3628
3629 if (c == NULL)
3630 return (0);
3631 /* there must be an official way to do this */
3632 mtx_lock_spin(&callout_lock);
3633 c_func = c->c_func;
3634 rval = callout_stop(c);
3635 mtx_unlock_spin(&callout_lock);
3636 item = c->c_arg;
3637 /* Do an extra check */
3638 if ((rval > 0) && (c_func == &ng_timeout_trapoline) &&
3638 if ((rval > 0) && (c_func == &ng_callout_trapoline) &&
3639 (NGI_NODE(item) == node)) {
3640 /*
3641 * We successfully removed it from the queue before it ran
3642 * So now we need to unreference everything that was
3643 * given extra references. (NG_FREE_ITEM does this).
3644 */
3645 NG_FREE_ITEM(item);
3646 }

--- 50 unchanged lines hidden ---
3639 (NGI_NODE(item) == node)) {
3640 /*
3641 * We successfully removed it from the queue before it ran
3642 * So now we need to unreference everything that was
3643 * given extra references. (NG_FREE_ITEM does this).
3644 */
3645 NG_FREE_ITEM(item);
3646 }

--- 50 unchanged lines hidden ---