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 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.

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.

See also:
lock, unlock

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.
See also:
unlock, restore

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 restore
See also:
lock, unlock

Definition 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.

See also:
lock, restore

Definition at line 106 of file asm-m68hc11/locks.h.