Specifications
Multithreading a Device Drive
r
11-13
pl is the interrupt priority level to be set after releasing the lock.
The RW_UNLOCK routine has no return value.
Finally, to deallocate a read/write lock, you use the RW_DEALLOC routine:
#include <sys/types.h>
#include <sys/ksynch.h>
#include <sys/ddi.h>
void RW_DEALLOC(lockp)
rwlock_t *lockp;
where:
lockp is a pointer to the read/write lock to be deallocated.
The RW_DEALLOC routine has no return value.
For additional information on the read/write lock interfaces, refer to the corresponding
system manual pages.
Sleep Locks 11
Sleep locks are used to provide exclusive access to a shared resource when spin locks can-
not be used. The sleep lock routines cause the calling LWP to block when the lock is not
available. These routines must be called from the base level of the device driver. Do not
use sleep locks in an interrupt service routine; use basic locks or read/write locks instead.
First, prior to using a sleep lock, you must define its associated lock information structure
which is of type lkinfo_t. This is done using the LKINFO_DECL(D5) kernel macro:
#include <sys/ksynch.h>
#include <sys/ddi.h>
LKINFO_DECL(var, name, flags)
where:
var is the name of the lock information structure of type lkinfo_t. The name cho-
sen should use a unique driver prefix to distinguish it from other lock name identifi-
ers.
name is a character string defining a name that identifies the lock. This name should
begin with the driver prefix and identifies the lock for the purpose of gathering sta-
tistics.
flags is either 0 or LK_NOSTATS. LK_NOSTATS prevents statistics gathering for the
lock.
Once the sleep lock has been defined, you must allocate and initialize it using the
SLEEP_ALLOC routine: