Using mutexes. STMicroelectronics OS20
Pubblicità
Pubblicità
7.2 Using mutexes 7 Mutexes
7.2
Using mutexes
Mutexes can only be used to protect a resource if all tasks that wish to use the resource also use the same mutex. It cannot protect a resource from a task that does not use the mutex and accesses the resource directly.
Mutexes allow at most one task access to the resource at any given time. Areas of code protected using mutexes are sometimes called critical regions.
The critical region is surrounded with calls to mutex_lock() at the start and mutex_release() at the end. Thus the first task which tries to enter the critical region successfully takes the mutex, and any others are forced to wait. When the task currently in the critical region leaves, it releases the mutex, and allows the first of the waiting tasks into the critical region.
7.3
Mutex header file: mutex.h
All the definitions related to mutexes are in the single header file, mutex.h
, see
and
.
mutex_create_fifo mutex_create_priority mutex_delete mutex_init_fifo mutex_init_priority mutex_lock mutex_release mutex_trylock
Function Description
Create a FIFO queued mutex
Create a priority queued mutex
Delete a mutex
Initialize a FIFO queued mutex
Initialize a priority queued mutex
Acquire a mutex, block if not available
Release a mutex
Try to get a mutex, fail if not available
Table 12: Functions defined in mutex.h
mutex_t
Type
A mutex
Table 13: Types define in mutex.h
Description
49
ADCS 7473749D
OS20 User Manual 7.3 Mutex header file: mutex.h
50
ADCS 7473749D
Scarica
Pubblicità