DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Multithreading device drivers

Protecting critical code

Critical code is a section of code that must be executed atomically; see ``Critical code section''. On uniprocessing configurations, only an interrupt generated by the hardware can interfere with the atomic execution, so issuing the spl(D3oddi) functions to prevent interrupts while the code is executing is adequate to protect the critical code.

On multiprocessing systems, interrupts can come from any processor, or two task-level processes executing on different processors could access the same resource. Consequently, the locking functions listed in ``Mutual exclusion locking functions'' must be used to provide mutual exclusion access to critical code.

Mutual exclusion locking functions

Function Description
atomic(D3oddi) family quick locks for basic arithmetic and bit operations
clockb(D3oddi), cunlockb(D3oddi) conditionally lock critical code sections
lockb(D3oddi), lockb5(D3oddi), unlockb(D3oddi) general locking functions
ilockb(D3oddi), iunlockb(D3oddi) block interrupts for short critical code sections
mdi_trylock(D3mdi),
mdi_tryunlock(D3mdi),
mdi_tryunlock_init(D3mdi)
MDI trylock functions
MPSTR_QLOCK(D3str), MPSTR_QRELE(D3str) lock STREAMS queue
MPSTR_STPLOCK(D3str), MPSTR_STPRELE(D3str) lock Stream head
tc_tlock(D3oddi), tc_tunlock(D3oddi),
tc_ctlock(D3oddi), tc_ctunlock(D3oddi)
mutual exclusion to a tty structure

Note the following about using the locking functions:


© 2005 The SCO Group, Inc. All rights reserved.