
CHAPTER 5 SYNCHRONOUS COMMUNICATION MANAGEMENT
User’s Manual U14833EJ2V0UM
65
5.6
Mutexes
Mutexes are objects used to perform exclusive control between tasks when common resources are used, and
support the priority inheritance and priority ceiling protocols as mechanisms for preventing the inversion of an
unlimited priority order that accompanies exclusive control.
5.6.1
Creating mutexes
Mutexes can be created either by issuing the service call (a)cre_mtx, or by specifying the static API CRE_MTX,
which performs equivalent processing to (a)cre_mtx when the system is initialized.
When (a)cre_mtx is issued, the attribute, priority order limit, etc., is stored in the block corresponding to the ID
number that specifies the mutex control block array, and that control block is then initialized.
The mutex ID number consists of a unique number of a value 1 or higher. The maximum value that can be
specified is the one defined in the system information table, up to a maximum of 0x7fff numbers.
5.6.2
Deleting mutexes
A mutex is deleted by issuing the service call del_mtx. When del_mtx is issued, the kernel invalidates the specified
mutex control block and puts the target mutex in the non-existent state.
Even if a task exists that is waiting to lock the mutex to be deleted, that mutex will still be deleted. In this case, all
the waiting tasks are released from the waiting state and the error code E_DLT indicating that the mutex has been
deleted is returned as the return value of the service call (loc_mtx, tloc_mtx).
Also, even if the target mutex has been locked by a task, the mutex will still be deleted. However, the task locking
the mutex will not be informed of its deletion. It is therefore necessary to inform this task of the mutex deletion by
performing processing such as issuing the service call unl_mtx to check for the return of the error code E_NOEXS or
E_ILUSE. Note also that if the current priority of the task locking the mutex has been raised via the priority inheritance
or priority ceiling protocol, the priority may be returned to the base priority by deletion of the locked mutex.
5.6.3
Priority inheritance protocol
The priority inheritance protocol is a mutex priority control protocol used to prevent the inversion of an unlimited
priority order. When processing related to a mutex with the TA_INHERIT attribute occurs, this protocol changes the
current priority value of the task locking the mutex to whichever is the highest of the following.
The task’s base priority value
The same priority value as the task with the highest priority among tasks waiting to lock a mutex with the attribute
TA_INHERIT
5.6.4
Priority ceiling protocol
The priority ceiling protocol is a mutex priority control protocol used to prevent the inversion of an unlimited priority
order. When a task locks a mutex with the attribute TA_CEILING, the priority of that task is changed to the top priority
value of the mutexes. Note that a task with a priority higher than this top priority cannot lock a mutex with the attribute
TA_CEILING.