This page is available in: en

tk_wai_sem

Wait on Semaphore

See Also

[C Language Interface]

ER ercd = tk_wai_sem ( ID semid, INT cnt, TMO tmout ) ;

[Parameters]

ID   semid    Semaphore ID
INT  cnt      Resource request count
TMO  tmout    timeout

[Return Parameters]

ER	ercd	Error code

[Error Codes]

E_OK     Normal completion
E_ID     Invalid ID number (semid is invalid or cannot be used)
E_NOEXS  Object does not exist (the semaphore specified in semid does not exist)
E_PAR    Parameter error (tmout ( ≤-2), cnt ≤ 0)
E_DLT    The object being waited for was deleted (the specified semaphore was deleted while waiting)
E_RLWAI  Wait state released (tk_rel_wai received in wait state)
E_TMOUT  Polling failed or timeout
E_CTX    Context error (issued from task-independent portion or in dispatch disabled state)

[Description]

From the semaphore specified in semid, gets the number of resources indicated in cnt. If the requested resources can be allocated, the task issuing this system call does not enter WAIT state but continues executing. In this case, the semaphore count (semcnt) is decreased by the value of cnt. If the resources are not available, the task issuing this system call enters WAIT state, and is put in the queue of tasks waiting for the semaphore. The semaphore count (semcnt) for this semaphore does not change in this case.

A maximum wait time timeout can be set in tmout. If the tmout time elapses before the wait release condition is met (tk_sig_sem is not executed), the system call terminates returning timeout error code E_TMOUT. Only positive values can be set in tmout. The time base for tmout (time unit) is the same as that for system time (= 1 ms).

When TMO_POL = 0 is set in tmout, this means 0 was specified as the timeout value, and E_TMOUT is returned without entering WAIT state even if no resources are acquired.

When TMO_FEVR =(-1) is set in tmout, this means infinity was specified as the timeout value and the task continues to wait for resource acquisition without timing out.

[Difference with T-Kernel]

E_DISWAI does not exist in error codes. This is because in µT-Kernel, there is no wait-disabled function.

Comments

Click here to Post a Comment