|
|
Trylocks are non-blocking lock operations that are provided for all categories of spin locks and sleep locks. A trylock returns a result indicating whether or not the lock was acquired; if the lock was in the locked state, the process does not block to wait for the lock. Using trylocks enables a driver to invoke a lock from a context that does not allow spinning or blocking.
As an example, a network driver uses a spin lock to ensure that the downstream service routine was MP-safe. The associated interrupt handler also attempts to send packets that are queued up for sending. An interrupt handler cannot block, but it can issue a trylock on the send routine. If it acquires the lock, it executes the send routine; if it cannot acquire the lock, it meant that the routine was being executed already so that the packets were being sent.
The logic of trylocks enables the driver send routine to be interrupted by a send-complete signal as well as receive interrupts if the hardware supports send/receive partitioning.