Notes
This module defines a mechanism for critical sections, that are required by the kernel in order to protect its resources from concurrent accesses. Since kernel-level critical sections utilize hardware features, this module is abstract. Therefore, an implementation must be provided by a port.
Porting
On a single-core platform, a critical section must disable all interrupts that call kernel functions. This includes both the alarm interrupt and the task interrupt. Potentially, additional measures must be taken on a multi-core platform, such as spinlocks. However, the implementation must ensure, that no two threads of execution can be inside a critical section simultaneously. Additionally, the implementation must support calls from both tasks and interrupt handlers.
Furthermore, the implementation should support nesting, although this is not strictly required by the kernel package. However, it can be assumed, that a call to ao_lock()
is always followed by a call to ao_unlock()
with the same parameter and from the same block scope, and that nesting calls do not overlap.
ao_lock_t * l1;
ao_lock_t * l2;
ao_lock(l1);
{
// ...
ao_lock(l2);
{
// ...
}
ao_unlock(l2);
// ...
}
ao_unlock(l1);
Types
ao_lock_t
typedef struct ao_lock_t ao_lock_t;
Represents a container for lock-related data. The actual make-up of this type is up to the implementation provided by the port. For the kernel modules, this type is completely opaque, that is, no assumptions are made about its inner structure.
Structs
ao_lock_t
struct ao_lock_t { };
Functions
ao_lock
ao_unlock
void ao_lock (ao_lock_t * l);
void ao_unlock(ao_lock_t * l);
Enters or exits a critical section, respectively.