Locking
Functions
__inline__ unsigned short lock (void)__inline__ void unlock (void)__inline__ void restore (unsigned short mask)__inline__ void interruption_point (void)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 whenlock()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_pointis defined for this.Function Documentation
__inline__ void interruption_point ( void )[static]Define an interruption point.
In a big masked section, it is sometimes useful to release the interrupt mask to accept pending interrupts.
This operation is intended to be used in some very specific situations where interrupts are masked and the code is ready to release the lock for a while. It must not be used within a critical section: it would break it.
Definition at line 135 of file asm-m68hc11/locks.h.
__inline__ unsigned short lock ( void )[static]Lock the processor to prevent interrupts to occur. When the processor is locked, interrupts are not accepted. They are deferred until the processor is unlocked. The previous locking mask is returned in the high part (bits 15..8) to avoid a tab instruction.
- Returns:
- the previous locking mask.
Definition at line 91 of file asm-m68hc11/locks.h.
__inline__ void restore ( unsigned short mask )[static]Restore the interrupt mask of the processor. The mask is assumed to be in the high part (bits 15..8) to avoid a tba instruction.
- Parameters:
mask the previous interrupt mask to restoreDefinition at line 118 of file asm-m68hc11/locks.h.
__inline__ void unlock ( void )[static]Unlock the processor to accept interrupts. When the processor is unlocked, interrupts are accepted. Use this operation if you want, authoritatively, accept the interrupts.
Definition at line 106 of file asm-m68hc11/locks.h.
Copyright (C) 1999, 2000, 2001, 2002, 2003 Stéphane Carrez, France
Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.