
2. TASK CONTROL FUNCTION
B–61863E–1/06
PMC CONTROL SOFTWARE
66
D To create an exclusive control type semaphore, use the system
call, os_mak2_sem. This system call specifies the owner priority
used at semaphore acquisition and whether to permit multiple
signaling.
If multiple signaling is permitted, an error does not occur when
a task acquiring a semaphore waits for the same semaphore. In
this case, the number of times the task is placed in the wait state
is counted. When signaling has been performed as many times
as the counted number, the task releases the semaphore.
Semaphore signal wait operation
D To wait for signaling of an exclusive control type semaphore, use
the system call, os_wait_sem.
D If another task has the ownership of the semaphore, the current
task is placed in the wait state.
D If the current task has semaphore ownership and multiple
signaling is enabled, the counter value is incremented.
D If the current task has ownership of the semaphore and multiple
signaling is disabled, an error code is returned.
if (sem owner = NONE) → If there is no semaphore owner
sem owner = current task → Acquiring the ownership of the semaphore
count = 1 → Setting the counter value to 1
if (owner pri < current pri) → If the priority is lower than the set value
current pri = owner pri → Changing the priority
else → If there is a semaphore owner
if (sem owner = current task)→ If the semaphore owner is the current task
if (multi signal = OK) → If multiple signaling is enabled
count++ → Incrementing the counter value
else → If multiple signaling is disabled
Error → Returning an error code
else → If the semaphore owner is another task
Wait → Entering the semaphore queue
OWNER Counter Semaphore queue
Wait (TASK A) A 1 → none
Wait (TASK B) A 1 → J
Wait (TASK C) A 1 → jJ
Wait (TASK A) A 2 → jj
Semaphore signaling
D To signal an exclusive control type semaphore, issue the system
call, os_sign_sem.
D If the task signaling the semaphore does not have ownership of
the semaphore, an error results.
D The ownership counter is decremented. When the counter
reaches 0, the task relinquishes the ownership. At this time, the
priority of the task is returned to its original value. If there are
waiting tasks, one task is selected according to the queue type, the
ownership is passed to that task, then the task is placed in the
ready state. If the priority of that task is lower than the value set
for the semaphore, the priority is increased to the set value.