|
|
int spl0(); int spl1(); int spl2();int spl3(); int spl4(); int spl5();
int spl6(); int spl7(); int spltty();
#include <sys/stream.h>
int splstr();
int splx(int previous);
/ Routines provided for backwards compatibility - they will be retired in a later release. /
int splbuf(); int splcli(); int splhi();
int splni(); int splpp();
The spl( ) functions block or allow servicing of interrupts on the processor on which the function is called. They are used in single-threaded drivers to protect critical code sections from specific levels of interrupts.
The spl* calls other than splx( ) do not take arguments.
splx does not return a value.
Note that, on multiprocessor systems, the spl( ) calls only set the priority level for the processor on which the code is executing. If it is possible for code executing on a different processor to access the same critical code, use spin locks to protect the resource; see ``Spin locks (ODDI)'' in HDK Technical Reference.
Use spltty to prevent interrupts associated with character lists (clist structures that are used to buffer data). It is not necessary to use spltty before calling any of the cblock or clist routines (see the getc(D3oddi) and putc(D3oddi) manual pages) because they themselves raise and restore the system priority level around their critical sections.
Do not manipulate clists in an interrupt routine. A driver's poll(D2oddi) routine runs at spl level 6 and can preempt another driver while it is manipulating clists. If your xxpoll( ) routine manipulates clist structures, you should ensure that it was not entered at an spl level of 5 or higher, to avoid corrupting the cfreelist (the kernel list of free clist structures).
Always store the previous priority level returned by an spl call and use splx to restore the previous level at the end of your critical code section (see ``Examples'' below).
Use of spl6, splbuf, splni, spl7 and splhi can cause the clock to lose time if the critical code section protected is too long. They also prevent other device drivers' poll( ) routines from being called. This may have an unpredictable effect on the behavior of other device drivers that require periodic execution of their poll( ) routines.
Be careful that code that executes in interrupt context does not drop the spl level below the level at which the interrupt occurred. This can corrupt the stack, which can cause loss of data or a system panic. The most common example of this is a driver's poll(D2oddi) foutine that manipulates clists. You should check the spl level at which poll( ) was called to guard against this (see ``Examples'' below).
With the high-precision system clock that is implemented in SCO OpenServer Release 5.0.6 and later, spl7( ) and splhi( ) do not disable the system clock as they do in earlier releases. See ``Clock, system'' in HDK Technical Reference for more information about the high-precision system clock.
``Synchronization primitives'' in HDK Technical Reference
``Critical code section'' in HDK Technical Reference
#include <sys/ipl.h>The next code fragment demonstrates the use of spltty in a driver task-time routine:xxpoll(ps) { /* If we were at spl5 or higher before xxpoll was called, LEAVE! */ if (ps >= SPL5) return; }
xxread(int dev); { /* set new spl and save old level in previous */ int previous = spltty(); . . /* perform clist operations */ . /* restore saved spl */ splx(previous); . . . }