
CHAPTER 13 SERVICE CALLS
User’s Manual U14833EJ2V0UM
226
Lock Mutex with Timeout
tloc_mtx
[Overview]
Locks a mutex (with timeout)
[C format]
#include <kernel.h>
ER tloc_mtx(ID mtxid, TMO tmout);
[Parameters]
I/O
Parameter
Description
I
ID
mtxid
ID number of mutex to be locked
I
TMO
tmout
Timeout time [milliseconds]
[Explanation]
The mutex specified by mtxid is locked.
If the target mutex can be locked, i.e., if locking the mutex is successful, the task continues processing. If the
mutex has the TA_CEILING attribute at this time and if the ceiling of the priority (ceilpri) specified when the mutex was
created is higher than the current priority of the task that locks the mutex, the current priority of the task is raised to
the ceiling value.
If the mutex has been already locked by another task, the task enters the waiting state for the time specified as
tmout and is registered to the waiting task queue in the order (on an FIFO basis or according to priority) specified
when the mutex was created. If the mutex has the TA_INHERIT attribute at this time and if the current priority of the
task that has entered the waiting state is higher than the current priority of the task that is locking the mutex, the
priority of the locking task is raised to the same current priority as the waiting task.
If the target mutex has the TA_CEILING attribute and if the base priority of the task is higher than the ceiling value
of the priority of the mutex, an error occurs and the error code E_ILUSE is returned.
The current priority raised by the mutex is changed to the base priority of the task when the task releases the lock
of the mutex (if the task locks two or more mutexes, when it releases the lock of all the mutexes).
Tasks placed in the waiting state due to tloc_mtx are released from waiting by one of the following occurrences.
1.
unl_mtx is issued and the task locks a new mutex (E_OK).
2.
The locking task is terminated and a new mutex is locked (E_OK).
3.
The specified time elapses and timeout occurs (E_TMOUT).
4.
(i)rel_wai is issued and the task is forcibly released from the waiting state (E_RLWAI).
5.
del_mtx is issued and the mutex is deleted (E_DLT).