Deleted Added
full compact
kern_event.c (193951) kern_event.c (195148)
1/*-
2 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
3 * Copyright 2004 John-Mark Gurney <jmg@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
3 * Copyright 2004 John-Mark Gurney <jmg@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/kern/kern_event.c 193951 2009-06-10 20:59:32Z kib $");
29__FBSDID("$FreeBSD: head/sys/kern/kern_event.c 195148 2009-06-28 21:49:43Z stas $");
30
31#include "opt_ktrace.h"
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/lock.h>
37#include <sys/mutex.h>

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

1601 * Walk down a list of knotes, activating them if their event has triggered.
1602 *
1603 * There is a possibility to optimize in the case of one kq watching another.
1604 * Instead of scheduling a task to wake it up, you could pass enough state
1605 * down the chain to make up the parent kqueue. Make this code functional
1606 * first.
1607 */
1608void
30
31#include "opt_ktrace.h"
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/lock.h>
37#include <sys/mutex.h>

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

1601 * Walk down a list of knotes, activating them if their event has triggered.
1602 *
1603 * There is a possibility to optimize in the case of one kq watching another.
1604 * Instead of scheduling a task to wake it up, you could pass enough state
1605 * down the chain to make up the parent kqueue. Make this code functional
1606 * first.
1607 */
1608void
1609knote(struct knlist *list, long hint, int islocked)
1609knote(struct knlist *list, long hint, int lockflags)
1610{
1611 struct kqueue *kq;
1612 struct knote *kn;
1610{
1611 struct kqueue *kq;
1612 struct knote *kn;
1613 int error;
1613
1614 if (list == NULL)
1615 return;
1616
1614
1615 if (list == NULL)
1616 return;
1617
1617 KNL_ASSERT_LOCK(list, islocked);
1618 KNL_ASSERT_LOCK(list, lockflags & KNF_LISTLOCKED);
1618
1619
1619 if (!islocked)
1620 if ((lockflags & KNF_LISTLOCKED) == 0)
1620 list->kl_lock(list->kl_lockarg);
1621
1622 /*
1623 * If we unlock the list lock (and set KN_INFLUX), we can eliminate
1624 * the kqueue scheduling, but this will introduce four
1625 * lock/unlock's for each knote to test. If we do, continue to use
1626 * SLIST_FOREACH, SLIST_FOREACH_SAFE is not safe in our case, it is
1627 * only safe if you want to remove the current item, which we are
1628 * not doing.
1629 */
1630 SLIST_FOREACH(kn, &list->kl_list, kn_selnext) {
1631 kq = kn->kn_kq;
1632 if ((kn->kn_status & KN_INFLUX) != KN_INFLUX) {
1633 KQ_LOCK(kq);
1621 list->kl_lock(list->kl_lockarg);
1622
1623 /*
1624 * If we unlock the list lock (and set KN_INFLUX), we can eliminate
1625 * the kqueue scheduling, but this will introduce four
1626 * lock/unlock's for each knote to test. If we do, continue to use
1627 * SLIST_FOREACH, SLIST_FOREACH_SAFE is not safe in our case, it is
1628 * only safe if you want to remove the current item, which we are
1629 * not doing.
1630 */
1631 SLIST_FOREACH(kn, &list->kl_list, kn_selnext) {
1632 kq = kn->kn_kq;
1633 if ((kn->kn_status & KN_INFLUX) != KN_INFLUX) {
1634 KQ_LOCK(kq);
1634 if ((kn->kn_status & KN_INFLUX) != KN_INFLUX) {
1635 if ((kn->kn_status & KN_INFLUX) == KN_INFLUX) {
1636 KQ_UNLOCK(kq);
1637 } else if ((lockflags & KNF_NOKQLOCK) != 0) {
1638 kn->kn_status |= KN_INFLUX;
1639 KQ_UNLOCK(kq);
1640 error = kn->kn_fop->f_event(kn, hint);
1641 KQ_LOCK(kq);
1642 kn->kn_status &= ~KN_INFLUX;
1643 if (error)
1644 KNOTE_ACTIVATE(kn, 1);
1645 KQ_UNLOCK_FLUX(kq);
1646 } else {
1635 kn->kn_status |= KN_HASKQLOCK;
1636 if (kn->kn_fop->f_event(kn, hint))
1637 KNOTE_ACTIVATE(kn, 1);
1638 kn->kn_status &= ~KN_HASKQLOCK;
1647 kn->kn_status |= KN_HASKQLOCK;
1648 if (kn->kn_fop->f_event(kn, hint))
1649 KNOTE_ACTIVATE(kn, 1);
1650 kn->kn_status &= ~KN_HASKQLOCK;
1651 KQ_UNLOCK(kq);
1639 }
1652 }
1640 KQ_UNLOCK(kq);
1641 }
1642 kq = NULL;
1643 }
1653 }
1654 kq = NULL;
1655 }
1644 if (!islocked)
1656 if ((lockflags & KNF_LISTLOCKED) == 0)
1645 list->kl_unlock(list->kl_lockarg);
1646}
1647
1648/*
1649 * add a knote to a knlist
1650 */
1651void
1652knlist_add(struct knlist *knl, struct knote *kn, int islocked)

--- 392 unchanged lines hidden ---
1657 list->kl_unlock(list->kl_lockarg);
1658}
1659
1660/*
1661 * add a knote to a knlist
1662 */
1663void
1664knlist_add(struct knlist *knl, struct knote *kn, int islocked)

--- 392 unchanged lines hidden ---