--- /usr/src/sys/conf/files Sun Aug 5 02:53:40 2007 +++ conf/files Wed Aug 8 13:09:09 2007 @@ -1427,6 +1427,7 @@ kern/kern_linker.c standard kern/kern_lock.c standard kern/kern_lockf.c standard +kern/kern_lockng.c standard kern/kern_malloc.c standard kern/kern_mbuf.c standard kern/kern_mib.c standard --- /usr/src/sys/sys/filedesc.h Tue Jun 26 18:22:34 2007 +++ sys/filedesc.h Wed Aug 8 13:14:44 2007 @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -60,7 +61,7 @@ u_short fd_cmask; /* mask for file creation */ u_short fd_refcnt; /* thread reference count */ u_short fd_holdcnt; /* hold count on structure + mutex */ - struct sx fd_sx; /* protects members of this struct */ + struct lockng fd_lock; /* protects members of this struct */ struct kqlist fd_kqlist; /* list of kqueues on this filedesc */ int fd_holdleaderscount; /* block fdfree() for shared close() */ int fd_holdleaderswakeup; /* fdfree() needs wakeup */ @@ -93,18 +94,29 @@ #ifdef _KERNEL /* Lock a file descriptor table. */ -#define FILEDESC_LOCK_INIT(fdp) sx_init(&(fdp)->fd_sx, "filedesc structure") -#define FILEDESC_LOCK_DESTROY(fdp) sx_destroy(&(fdp)->fd_sx) -#define FILEDESC_LOCK(fdp) (&(fdp)->fd_sx) -#define FILEDESC_XLOCK(fdp) sx_xlock(&(fdp)->fd_sx) -#define FILEDESC_XUNLOCK(fdp) sx_xunlock(&(fdp)->fd_sx) -#define FILEDESC_SLOCK(fdp) sx_slock(&(fdp)->fd_sx) -#define FILEDESC_SUNLOCK(fdp) sx_sunlock(&(fdp)->fd_sx) - -#define FILEDESC_LOCK_ASSERT(fdp) sx_assert(&(fdp)->fd_sx, SX_LOCKED | \ - SX_NOTRECURSED) -#define FILEDESC_XLOCK_ASSERT(fdp) sx_assert(&(fdp)->fd_sx, SX_XLOCKED | \ - SX_NOTRECURSED) +#define FILEDESC_LOCK_INIT(fdp) \ + lockmgr_init(&(fdp)->fd_lock, "filedesc structure") +#define FILEDESC_LOCK_DESTROY(fdp) \ + lockmgr_destroy(&(fdp)->fd_lock) +#define FILEDESC_LOCK(fdp) (&(fdp)->fd_lock) +#define FILEDESC_XLOCK(fdp) do { \ + if (lockmgr2(&(fdp)->fd_lock, LCK_EXCLUSIVE, NULL, curthread)) \ + panic("%s: lockmgr2 error\n", __func__); \ +} while (0) +#define FILEDESC_XUNLOCK(fdp) do { \ + if (lockmgr2(&(fdp)->fd_lock, LCK_RELEASE, NULL, curthread)) \ + panic("%s: lockmgr2 error\n", __func__); \ +} while (0) +#define FILEDESC_SLOCK(fdp) do { \ + if (lockmgr2(&(fdp)->fd_lock, LCK_SHARE, NULL, curthread)) \ + panic("%s: lockmgr2 error\n", __func__); \ +} while (0) +#define FILEDESC_SUNLOCK(fdp) FILEDESC_XUNLOCK(fdp) + +#define FILEDESC_LOCK_ASSERT(fdp) \ + lockmgr_assert(&(fdp)->fd_lock, CA_LOCKED | CA_NOTRECURSED, 0) +#define FILEDESC_XLOCK_ASSERT(fdp) \ + lockmgr_assert(&(fdp)->fd_lock, CA_XLOCKED | CA_NOTRECURSED, 0) struct thread;