Subject: Mapping NetBSD Kernel locks to Solaris
To: None <tech-kern@netbsd.org>
From: Darren Reed <darrenr@reed.wattle.id.au>
List: tech-kern
Date: 03/21/2001 23:14:44
Having experienced the somewhat convenient and easy to use locking
interface in Solaris, I tried to create a set of macros that bring
that functionality to NetBSD.
I managed to make some progress, but started bumping my head against
things in NetBSD...anyone care to add some enlightenment ? There are
holes which can't be filled but I've applied putty to try stop leaks.
Darren
/*
* Solaris compatible interface.
*/
typedef struct simplelock kmutex_t;
#define MUTEX_ADAPTIVE LK_RECURSEFAIL
#define MUTEX_SPIN LK_SPIN|LK_RECURSEFAIL
#define MUTEX_DRIVER LK_RECURSEFAIL
#define MUTEX_DEFAULT LK_RECURSEFAIL
#define MUTEX_HELD(x)
#define MUTEX_NOT_HELD(x)
#define mutex_init(mp, name, type, arg) spinlockinit(mp, name, arg)
#define mutex_destroy(mp)
#define mutex_enter(mp) simple_lock(mp)
#define mutex_exit(mp) simple_unlock(mp)
#define mutex_owned(mp) simple_lock_held(mp)
#define mutex_tryenter(mp) simple_lock_try(mp)
typedef struct lock krwlock_t;
#define RW_READER LK_SHARED
#define RW_WRITER LK_EXCLUSIVE
#define RW_DRIVER LK_SPIN
#define RW_DEFAULT LK_SPIN
#define RW_READ_HELD(x) (lockstatus(rwlp) == LK_SHARED)
#define RW_WRITE_HELD(x) (lockstatus(rwlp) == LK_EXCLUSIVE)
#define RW_LOCK_HELD(x) (lockstatus(rwlp) == LK_SHARED)
#define RW_ISWRITER(x) (lockstatus(rwlp) == LK_SHARED)
#define rw_init(rwlp, name, type, arg) lockinit(rwlp,
#define rw_destroy(rwlp)
#define rw_enter(rwlp, type) lockmgr(rwlp)
#define rw_exit(rwlp) lockmgr(rwlp, type)
#define rw_tryenter(rwlp, type) lockmgr(rwlp, LK_RELEASE)
#define rw_downgrade(rwlp) lockmgr(rwlp, LK_DOWNGRADE)
#define rw_tryupgrade(rwlp) lockmgr(rwlp, LK_UPGRADE)
#define rw_read_locked(rwlp) (lockstatus(rwlp) == LK_SHARED)