
B–61863E–1/06
2. TASK CONTROL FUNCTION
PMC CONTROL SOFTWARE
67
if (sem owner = current task) → If the current task is the semaphore owner
count-- → Decrementing the counter
if (count = 0) → If the counter is 0
sem owner = NONE → Returning the ownership of the semaphore
current pri = old pri → Returning the priority to its original value
if (Wait task = YES) → If there are waiting tasks
sem owner = Wait task → Passing the ownership of the semaphore to the
task at the top of the queue
Signal → Releasing the wait state
if (owner pri < Wait pri) → If the priority is lower than the set value
Wait pri = owner pri → Changing the priority
else → If the current task is not the semaphore owner
Error → Returning an error code
OWNER Counter Semaphore queue
A 2 → jj
Signal(TASK A) A 1 → jj
Signal(TASK A) B 1 → j
Signal(TASK B) C 1 → none
Signal(TASK C) none 0 → none
“How to perform exclusive control ”
With an exclusive control type semaphore, exclusive control is
performed for resources shared by multiple tasks as shown below:
Using the resourece
os_wait_sem
os_sign_sem
Acquiring the ownership
of the resource
Relinquishing the
ownership of the resource
D Before a resource can be used, its
ownership must be acquired using
os_wait_sem.
D If an owner already exists, the task
is placed in the wait state.
D After the resource is used, its
ownership is relinquished using
os_sign_sem.
D At the same time, the ownership is
passed to the task at the top of the
queue waiting for the semaphore.)
(3) Changing the semaphore queue type
The default semaphore queue is an FIFO (first-in first-out) queue.
This queue type can be changed to the priority queue type using the
system call, os_que_sem. In the priority queue, tasks are attached in
order of priority.
FIFO queue
current task pri=15
↓ sem wait queue ↓
wait →jjjJ
pri 12 14 20 15
Priority queue
current task pri=15
↓ sem wait queue ↓
wait →jjJj
pri 12 14 15 20