Date: Mon, 26 Mar 2012 09:34:17 +0000 (UTC) From: "Alexander V. Chernikov" <melifaro@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r233505 - in head: share/man/man9 sys/kern sys/sys Message-ID: <201203260934.q2Q9YHFV025590@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: melifaro Date: Mon Mar 26 09:34:17 2012 New Revision: 233505 URL: http://svn.freebsd.org/changeset/base/233505 Log: - Add knlist_init_rw_reader() function to kqueue(9). Function acquired reader lock if needed. Assert check for reader or writer lock (RA_LOCKED / RA_UNLOCKED) - While here, add knlist_init_mtx.9 to MLINKS and fix some style(9) issues Reviewed by: glebius Approved by: ae(mentor) MFC after: 2 weeks Modified: head/share/man/man9/Makefile head/share/man/man9/kqueue.9 head/sys/kern/kern_event.c head/sys/sys/event.h Modified: head/share/man/man9/Makefile ============================================================================== --- head/share/man/man9/Makefile Mon Mar 26 09:31:15 2012 (r233504) +++ head/share/man/man9/Makefile Mon Mar 26 09:34:17 2012 (r233505) @@ -773,6 +773,8 @@ MLINKS+=kqueue.9 knlist_add.9 \ kqueue.9 knlist_destroy.9 \ kqueue.9 knlist_empty.9 \ kqueue.9 knlist_init.9 \ + kqueue.9 knlist_init_mtx.9 \ + kqueue.9 knlist_init_rw_reader.9 \ kqueue.9 knlist_remove.9 \ kqueue.9 knlist_remove_inevent.9 \ kqueue.9 knote_fdclose.9 \ Modified: head/share/man/man9/kqueue.9 ============================================================================== --- head/share/man/man9/kqueue.9 Mon Mar 26 09:31:15 2012 (r233504) +++ head/share/man/man9/kqueue.9 Mon Mar 26 09:34:17 2012 (r233505) @@ -24,14 +24,14 @@ .\" .\" $FreeBSD$ .\" -.Dd February 25, 2012 +.Dd March 26, 2012 .Dt KQUEUE 9 .Os .Sh NAME .Nm kqueue_add_filteropts , kqueue_del_filteropts , .Nm kqfd_register , .Nm knote_fdclose , -.Nm knlist_init , knlist_init_mtx , +.Nm knlist_init , knlist_init_mtx , knlist_init_rw_reader , .Nm knlist_add , knlist_remove , knlist_remove_inevent , knlist_empty , .Nm knlist_clear , knlist_delete , knlist_destroy , .Nm KNOTE_LOCKED , KNOTE_UNLOCKED @@ -57,6 +57,8 @@ .Ft void .Fn knlist_init_mtx "struct knlist *knl" "struct mtx *lock" .Ft void +.Fn knlist_init_rw_reader "struct knlist *knl" "struct rwlock *lock" +.Ft void .Fn knlist_add "struct knlist *knl" "struct knote *kn" "int islocked" .Ft void .Fn knlist_remove "struct knlist *knl" "struct knote *kn" "int islocked" @@ -259,8 +261,10 @@ If used, the .Vt knlist must be initialized with either .Fn knlist_init +, +.Fn knlist_init_mtx or -.Fn knlist_init_mtx . +.Fn knlist_init_rw_reader . The .Vt knlist structure may be embedded into the object structure. @@ -305,6 +309,19 @@ style lock. .Pp The function +.Fn knlist_init_rw_reader +may be used to initialize a +.Vt knlist +when +.Fa lock +is a +.Xr rwlock 9 +read lock. +Lock is acquired via +.Fn rw_rlock +function. +.Pp +The function .Fn knlist_empty returns true when there are no .Vt knotes Modified: head/sys/kern/kern_event.c ============================================================================== --- head/sys/kern/kern_event.c Mon Mar 26 09:31:15 2012 (r233504) +++ head/sys/kern/kern_event.c Mon Mar 26 09:34:17 2012 (r233505) @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include <sys/kernel.h> #include <sys/lock.h> #include <sys/mutex.h> +#include <sys/rwlock.h> #include <sys/proc.h> #include <sys/malloc.h> #include <sys/unistd.h> @@ -1869,6 +1870,7 @@ knlist_remove_inevent(struct knlist *knl int knlist_empty(struct knlist *knl) { + KNL_ASSERT_LOCKED(knl); return SLIST_EMPTY(&knl->kl_list); } @@ -1882,27 +1884,59 @@ static void knlist_mtx_unlock(void *arg) static void knlist_mtx_lock(void *arg) { + mtx_lock((struct mtx *)arg); } static void knlist_mtx_unlock(void *arg) { + mtx_unlock((struct mtx *)arg); } static void knlist_mtx_assert_locked(void *arg) { + mtx_assert((struct mtx *)arg, MA_OWNED); } static void knlist_mtx_assert_unlocked(void *arg) { + mtx_assert((struct mtx *)arg, MA_NOTOWNED); } +static void +knlist_rw_rlock(void *arg) +{ + + rw_rlock((struct rwlock *)arg); +} + +static void +knlist_rw_runlock(void *arg) +{ + + rw_runlock((struct rwlock *)arg); +} + +static void +knlist_rw_assert_locked(void *arg) +{ + + rw_assert((struct rwlock *)arg, RA_LOCKED); +} + +static void +knlist_rw_assert_unlocked(void *arg) +{ + + rw_assert((struct rwlock *)arg, RA_UNLOCKED); +} + void knlist_init(struct knlist *knl, void *lock, void (*kl_lock)(void *), void (*kl_unlock)(void *), @@ -1942,6 +1976,14 @@ knlist_init_mtx(struct knlist *knl, stru } void +knlist_init_rw_reader(struct knlist *knl, struct rwlock *lock) +{ + + knlist_init(knl, lock, knlist_rw_rlock, knlist_rw_runlock, + knlist_rw_assert_locked, knlist_rw_assert_unlocked); +} + +void knlist_destroy(struct knlist *knl) { Modified: head/sys/sys/event.h ============================================================================== --- head/sys/sys/event.h Mon Mar 26 09:31:15 2012 (r233504) +++ head/sys/sys/event.h Mon Mar 26 09:34:17 2012 (r233505) @@ -234,6 +234,7 @@ struct thread; struct proc; struct knlist; struct mtx; +struct rwlock; extern void knote(struct knlist *list, long hint, int lockflags); extern void knote_fork(struct knlist *list, int pid); @@ -245,6 +246,7 @@ extern void knlist_init(struct knlist *k void (*kl_lock)(void *), void (*kl_unlock)(void *), void (*kl_assert_locked)(void *), void (*kl_assert_unlocked)(void *)); extern void knlist_init_mtx(struct knlist *knl, struct mtx *lock); +extern void knlist_init_rw_reader(struct knlist *knl, struct rwlock *lock); extern void knlist_destroy(struct knlist *knl); extern void knlist_cleardel(struct knlist *knl, struct thread *td, int islocked, int killkn);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203260934.q2Q9YHFV025590>