Main Page | Modules | Data Structures | File List | Data Fields | Globals

Locking


Detailed Description

Locking operations are defined to allow the use of two strategies to protect critical sections from interrupts:

Lock/Unlock
This simple strategy consists in disabling interrupts (sei ) and enabling them after the critical section. In general, this method assumes the processor accepts interrupts when lock() is called. This strategy is not suitable to implement functions that will be called with interrupts masked because this will create a side-effect: enable interrupts.

Example:

lock (); ... unlock ();

Lock/Restore
This strategy is suitable to protect critical sections in functions that will be called with interrupts masked. The processor mask is saved before locking interrupts. It is restored at the end of the critical section. When entering the critical section, if interrupts are masked, they will remain masked at end of critical section. There is no side effect.

Example:

unsigned short mask;

mask = lock (); ... restore (mask);

Sometimes it is necessary to allow interrupt processing again to make sure interrupts are not masked for a too long period. In this case, unlocking and relocking interrupts afterwards allows this. The function interruption_point is defined for this.


Generated on Sat Apr 10 17:08:24 2004 for BeeOS by doxygen 1.3.6-20040222