kern_event.c (e11e3f187d4a8c39f0e06dfdba09881354cbbf56) kern_event.c (d8b0556c6dcaf4c506039f86af2b52b29524f89e)
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:

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

203#define KNL_ASSERT_LOCK(knl, islocked) do { \
204 if (islocked) \
205 KNL_ASSERT_LOCKED(knl); \
206 else \
207 KNL_ASSERT_UNLOCKED(knl); \
208} while (0)
209#ifdef INVARIANTS
210#define KNL_ASSERT_LOCKED(knl) do { \
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:

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

203#define KNL_ASSERT_LOCK(knl, islocked) do { \
204 if (islocked) \
205 KNL_ASSERT_LOCKED(knl); \
206 else \
207 KNL_ASSERT_UNLOCKED(knl); \
208} while (0)
209#ifdef INVARIANTS
210#define KNL_ASSERT_LOCKED(knl) do { \
211 if (!knl->kl_locked((knl)->kl_lockarg)) \
212 panic("knlist not locked, but should be"); \
211 knl->kl_assert_locked((knl)->kl_lockarg); \
213} while (0)
212} while (0)
214#define KNL_ASSERT_UNLOCKED(knl) do { \
215 if (knl->kl_locked((knl)->kl_lockarg)) \
216 panic("knlist locked, but should not be"); \
213#define KNL_ASSERT_UNLOCKED(knl) do { \
214 knl->kl_assert_unlocked((knl)->kl_lockarg); \
217} while (0)
218#else /* !INVARIANTS */
219#define KNL_ASSERT_LOCKED(knl) do {} while(0)
220#define KNL_ASSERT_UNLOCKED(knl) do {} while (0)
221#endif /* INVARIANTS */
222
223#define KN_HASHSIZE 64 /* XXX should be tunable */
224#define KN_HASH(val, mask) (((val) ^ (val >> 8)) & (mask))

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

572 if (error)
573 goto done2;
574
575 /* An extra reference on `nfp' has been held for us by falloc(). */
576 kq = malloc(sizeof *kq, M_KQUEUE, M_WAITOK | M_ZERO);
577 mtx_init(&kq->kq_lock, "kqueue", NULL, MTX_DEF|MTX_DUPOK);
578 TAILQ_INIT(&kq->kq_head);
579 kq->kq_fdp = fdp;
215} while (0)
216#else /* !INVARIANTS */
217#define KNL_ASSERT_LOCKED(knl) do {} while(0)
218#define KNL_ASSERT_UNLOCKED(knl) do {} while (0)
219#endif /* INVARIANTS */
220
221#define KN_HASHSIZE 64 /* XXX should be tunable */
222#define KN_HASH(val, mask) (((val) ^ (val >> 8)) & (mask))

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

570 if (error)
571 goto done2;
572
573 /* An extra reference on `nfp' has been held for us by falloc(). */
574 kq = malloc(sizeof *kq, M_KQUEUE, M_WAITOK | M_ZERO);
575 mtx_init(&kq->kq_lock, "kqueue", NULL, MTX_DEF|MTX_DUPOK);
576 TAILQ_INIT(&kq->kq_head);
577 kq->kq_fdp = fdp;
580 knlist_init(&kq->kq_sel.si_note, &kq->kq_lock, NULL, NULL, NULL);
578 knlist_init_mtx(&kq->kq_sel.si_note, &kq->kq_lock);
581 TASK_INIT(&kq->kq_task, 0, kqueue_task, kq);
582
583 FILEDESC_XLOCK(fdp);
584 SLIST_INSERT_HEAD(&fdp->fd_kqlist, kq, kq_list);
585 FILEDESC_XUNLOCK(fdp);
586
587 finit(fp, FREAD | FWRITE, DTYPE_KQUEUE, kq, &kqueueops);
588 fdrop(fp, td);

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

1718 return SLIST_EMPTY(&knl->kl_list);
1719}
1720
1721static struct mtx knlist_lock;
1722MTX_SYSINIT(knlist_lock, &knlist_lock, "knlist lock for lockless objects",
1723 MTX_DEF);
1724static void knlist_mtx_lock(void *arg);
1725static void knlist_mtx_unlock(void *arg);
579 TASK_INIT(&kq->kq_task, 0, kqueue_task, kq);
580
581 FILEDESC_XLOCK(fdp);
582 SLIST_INSERT_HEAD(&fdp->fd_kqlist, kq, kq_list);
583 FILEDESC_XUNLOCK(fdp);
584
585 finit(fp, FREAD | FWRITE, DTYPE_KQUEUE, kq, &kqueueops);
586 fdrop(fp, td);

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

1716 return SLIST_EMPTY(&knl->kl_list);
1717}
1718
1719static struct mtx knlist_lock;
1720MTX_SYSINIT(knlist_lock, &knlist_lock, "knlist lock for lockless objects",
1721 MTX_DEF);
1722static void knlist_mtx_lock(void *arg);
1723static void knlist_mtx_unlock(void *arg);
1726static int knlist_mtx_locked(void *arg);
1727
1728static void
1729knlist_mtx_lock(void *arg)
1730{
1731 mtx_lock((struct mtx *)arg);
1732}
1733
1734static void
1735knlist_mtx_unlock(void *arg)
1736{
1737 mtx_unlock((struct mtx *)arg);
1738}
1739
1724
1725static void
1726knlist_mtx_lock(void *arg)
1727{
1728 mtx_lock((struct mtx *)arg);
1729}
1730
1731static void
1732knlist_mtx_unlock(void *arg)
1733{
1734 mtx_unlock((struct mtx *)arg);
1735}
1736
1740static int
1741knlist_mtx_locked(void *arg)
1737static void
1738knlist_mtx_assert_locked(void *arg)
1742{
1739{
1743 return (mtx_owned((struct mtx *)arg));
1740 mtx_assert((struct mtx *)arg, MA_OWNED);
1744}
1745
1741}
1742
1743static void
1744knlist_mtx_assert_unlocked(void *arg)
1745{
1746 mtx_assert((struct mtx *)arg, MA_NOTOWNED);
1747}
1748
1746void
1747knlist_init(struct knlist *knl, void *lock, void (*kl_lock)(void *),
1749void
1750knlist_init(struct knlist *knl, void *lock, void (*kl_lock)(void *),
1748 void (*kl_unlock)(void *), int (*kl_locked)(void *))
1751 void (*kl_unlock)(void *),
1752 void (*kl_assert_locked)(void *), void (*kl_assert_unlocked)(void *))
1749{
1750
1751 if (lock == NULL)
1752 knl->kl_lockarg = &knlist_lock;
1753 else
1754 knl->kl_lockarg = lock;
1755
1756 if (kl_lock == NULL)
1757 knl->kl_lock = knlist_mtx_lock;
1758 else
1759 knl->kl_lock = kl_lock;
1760 if (kl_unlock == NULL)
1761 knl->kl_unlock = knlist_mtx_unlock;
1762 else
1763 knl->kl_unlock = kl_unlock;
1753{
1754
1755 if (lock == NULL)
1756 knl->kl_lockarg = &knlist_lock;
1757 else
1758 knl->kl_lockarg = lock;
1759
1760 if (kl_lock == NULL)
1761 knl->kl_lock = knlist_mtx_lock;
1762 else
1763 knl->kl_lock = kl_lock;
1764 if (kl_unlock == NULL)
1765 knl->kl_unlock = knlist_mtx_unlock;
1766 else
1767 knl->kl_unlock = kl_unlock;
1764 if (kl_locked == NULL)
1765 knl->kl_locked = knlist_mtx_locked;
1768 if (kl_assert_locked == NULL)
1769 knl->kl_assert_locked = knlist_mtx_assert_locked;
1766 else
1770 else
1767 knl->kl_locked = kl_locked;
1771 knl->kl_assert_locked = kl_assert_locked;
1772 if (kl_assert_unlocked == NULL)
1773 knl->kl_assert_unlocked = knlist_mtx_assert_unlocked;
1774 else
1775 knl->kl_assert_unlocked = kl_assert_unlocked;
1768
1769 SLIST_INIT(&knl->kl_list);
1770}
1771
1772void
1776
1777 SLIST_INIT(&knl->kl_list);
1778}
1779
1780void
1781knlist_init_mtx(struct knlist *knl, struct mtx *lock)
1782{
1783
1784 knlist_init(knl, lock, NULL, NULL, NULL, NULL);
1785}
1786
1787void
1773knlist_destroy(struct knlist *knl)
1774{
1775
1776#ifdef INVARIANTS
1777 /*
1778 * if we run across this error, we need to find the offending
1779 * driver and have it call knlist_clear.
1780 */

--- 249 unchanged lines hidden ---
1788knlist_destroy(struct knlist *knl)
1789{
1790
1791#ifdef INVARIANTS
1792 /*
1793 * if we run across this error, we need to find the offending
1794 * driver and have it call knlist_clear.
1795 */

--- 249 unchanged lines hidden ---