30.12.2013 Views

T-Kernel Specification (1.B0.02)

T-Kernel Specification (1.B0.02)

T-Kernel Specification (1.B0.02)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

112 CHAPTER 4. T-KERNEL/OS FUNCTIONS<br />

tk loc mtx<br />

Lock Mutex<br />

[C Language Interface]<br />

ER ercd = tk_loc_mtx ( ID mtxid, TMO tmout ) ;<br />

[Parameters]<br />

ID mtxid Mutex ID<br />

TMO tmout Timeout designation<br />

[Return Parameters]<br />

ER ercd Error code<br />

[Error Codes]<br />

E OK<br />

E ID<br />

E NOEXS<br />

E PAR<br />

E DLT<br />

E RLWAI<br />

E DISWAI<br />

E TMOUT<br />

E CTX<br />

E ILUSE<br />

Normal completion<br />

Invalid ID number (mtxid is invalid or cannot be used)<br />

Object does not exist (the mutex designated in mtxid does not exist)<br />

Parameter error (tmout ≤ (−2))<br />

The object being waited for was deleted (the mutex was deleted while waiting for a lock)<br />

Wait state released (tk rel wai received in wait state)<br />

Wait released by wait disabled state<br />

Polling failed or timeout<br />

Context error (issued from task-independent portion or in dispatch disabled state)<br />

Illegal use (multiple lock, or upper priority limit exceeded)<br />

[Description]<br />

Locks the mutex designated in mtxid. If the mutex can be locked immediately, the task issuing this<br />

system call continue executing without entering WAIT state, and the mutex goes to locked status. If<br />

the mutex cannot be locked, the task issuing this system call enters WAIT state. That is, the task is<br />

put in the queue of this mutex.<br />

A maximum wait time (timeout) can be set in tmout. If the tmout time elapses before the wait release<br />

condition is met, the system call terminates, returning timeout error code E TMOUT. Only positive values<br />

can be set in tmout. The time base for tmout (time unit) is the same as that for system time (= 1 ms).<br />

When TMO POL = 0 is set in tmout, this means 0 was designated as the timeout value, and E TMOUT is<br />

returned without entering WAIT state even if the resource cannot be locked. When TMO FEVR = (−1)<br />

is set in tmout, this means infinity was designated as the timeout value, and the task continues wait to<br />

until the resource is locked.<br />

If the invoking task has already locked the designated mutex, error code E ILUSE (multiple lock) is<br />

returned.<br />

Copyright c○ 2002, 2003 by T-Engine Forum<br />

T-<strong>Kernel</strong> <strong>1.B0.02</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!