From: François Tigeot Date: Fri, 22 Jun 2012 13:55:49 +0000 (+0200) Subject: kernel: add a LOCK_SYSINIT helper macro X-Git-Tag: v3.2.0~471 X-Git-Url: http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/5d101ab93eae8e6adeabb86112f41964cbb588a0 kernel: add a LOCK_SYSINIT helper macro * Inspired from FreeBSD's MTX_SYSINIT * This will help with driver porting --- diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index 290b922..0b70003 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -707,3 +707,8 @@ lockmgr_printinfo(struct lock *lkp) kprintf(" with %d pending", lkp->lk_waitcount); } +void +lock_sysinit(struct lock_args *arg) +{ + lockinit(arg->la_lock, arg->la_desc, 0, LK_CANRECURSE); +} diff --git a/sys/sys/lock.h b/sys/sys/lock.h index 8d099e6..8e4174e 100644 --- a/sys/sys/lock.h +++ b/sys/sys/lock.h @@ -188,9 +188,15 @@ struct lock { void dumplockinfo(struct lock *lkp); struct proc; +struct lock_args { + struct lock *la_lock; + const char *la_desc; +}; + void lockinit (struct lock *, const char *wmesg, int timo, int flags); void lockreinit (struct lock *, const char *wmesg, int timo, int flags); void lockuninit(struct lock *); +void lock_sysinit(struct lock_args *); #ifdef DEBUG_LOCKS int debuglockmgr (struct lock *, u_int flags, const char *, @@ -210,7 +216,16 @@ int lockowned (struct lock *); int lockcount (struct lock *); int lockcountnb (struct lock *); +#define LOCK_SYSINIT(name, lock, desc) \ + static struct lock_args name##_args = { \ + (lock), \ + (desc) \ + }; \ + SYSINIT(name##_lock_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, \ + lock_sysinit, &name##_args); \ + SYSUNINIT(name##_lock_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, \ + lockuninit, (lock)) + #endif /* _KERNEL */ #endif /* _KERNEL || _KERNEL_STRUCTURES */ #endif /* _SYS_LOCK_H_ */ -