Everything

twai_sem

Outline
Acquire semaphore resource (with time-out).
C format
 ER      twai_sem (ID semid, TMO tmout);
Parameter(s)
I/O
Parameter
Description
I
 ID      semid;
ID number of the semaphore.
I
 TMO     tmout;
Specified time-out (in millisecond).
TMO_FEVR: Waiting forever.
TMO_POL: Polling.
Value: Specified time-out.

Explanation
This service call acquires a resource from the semaphore specified by parameter semid (subtracts 1 from the semaphore counter).
If no resources are acquired from the target semaphore when service call is issued this (no available resources exist), this service call does not acquire resources but queues the invoking task to the target semaphore wait queue and moves it from the RUNNING state to the WAITING state with time-out (resource acquisition wait state).
The WAITING state for a semaphore resource is cancelled in the following cases.
WAITING State for a Semaphore Resource Cancel Operation
Return Value
The resource was released to the target semaphore as a result of issuing sig_sem.
E_OK
The resource was released to the target semaphore as a result of issuing isig_sem.
E_OK
Forced release from waiting (accept rel_wai while waiting).
E_RLWAI
Forced release from waiting (accept irel_wai while waiting).
E_RLWAI
The time specified by tmout has elapsed.
E_TMOUT
Forced release from waiting (accept del_sem while waiting).
E_DLT

Note 1 Invoking tasks are queued to the target semaphore wait queue in the order specified at creating the semaphore (FIFO order or current priority order).
Note 2 TMO_FEVR is specified for wait time tmout, processing equivalent to wai_sem will be executed. When TMO_POL is specified, processing equivalent to pol_sem will be executed.
Return value
Macro
Value
Description
E_OK
0
Normal completion.
E_PAR
-17
Parameter error.
- tmout < -1
- tmout > (0x7FFFFFFF - TIC_NUME) / TIC_DENO
E_ID
-18
Invalid ID number.
- semid < 0
- semid > VTMAX_SEM
E_CTX
-25
Context error.
- This service call was issued from a non-task.
- This service call was issued in the CPU locked state.
- This service call was issued in the dispatching disabled state.
- This service call was issued in the status "PSW.IPL > kernel interrupt mask level".
E_MACV
-26
Memory access violation.
- Stack pointer points out of user stack for invoking task.
E_NOEXS
-42
Non-existent object.
- The semaphore specified by semid does not exist.
E_RLWAI
-49
Forced release from the WAITING state.
- Accept rel_wai/irel_wai while waiting.
E_TMOUT
-50
Polling failure or specified time has elapsed.
E_DLT
-51
Waiting object deleted.
- Accept del_sem while waiting.