
CHAPTER 6 MEMORY MANAGEMENT
User’s Manual U14833EJ2V0UM
78
If the queue does not contain a memory space large enough for acquisition, the task is put in the memory block
acquisition waiting state, and waits until a memory block has been acquired, in the case of get_mpl or until either a
memory block has been acquired or a specified time has elapsed, in the case of tget_mpl. The issuance of
(i)pget_mpl results in an error, and the error code E_TMOUT is returned, indicating that polling failed.
Tasks in the memory block acquisition waiting state are registered in the waiting task queue of the memory pool.
The waiting order at this time depends on the attribute of the memory pool: in FIFO order if the attribute is TA_TFIFO
or in priority order if the attribute is TA_TPRI, and if (i)rel_mpl is issued and there is sufficient memory space in the
memory pool, memory blocks are acquired in the order they are queued, and the task is released from waiting.
Note that because 0 is stored in the top four bytes of the acquired memory block, when this memory block is
transmitted to a mailbox as a message, because no value other than 0 is stored in this area (which is used by the
kernel to manage the message), it is possible to check whether a memory block has been registered in the mailbox by
checking the top four bytes.
Note also that when there are multiple tasks simultaneously waiting to acquire a memory block from the same
memory pool, if one of those tasks has requested a large-sized memory block, because the memory block acquisition
feasibility check is performed in the order in which the tasks are waiting in the queue, a later task may be blocked and
forced to wait even if there is sufficient memory space for it to acquire the requested memory block (see
Figure 6-8
).
In other words, if the memory pool has the attribute TA_TFIFO and there are tasks already waiting, a task coming
later will be unable to acquire a memory block, regardless of the requested size, and will be forced to wait, or polling
will fail. If there are tasks waiting in the queue of a memory pool with the attribute TA_TPRI, memory block acquisition
will only be possible if a memory block of the requested size is available and if the priority of the requesting task is
higher than that of the task at the top of the queue. If ipget_mpl is issued for a memory pool with the attribute
TA_TPRI from an interrupt servicing routine, because the interrupt processing has a higher priority than the task
processing, only the check to ascertain whether an acquirable block is available will be made.
Figure 6-8. Case When Task Is Waiting Even Though Sufficient Area Is Available
Header
Total memory pool size
Acquisition complete
Header
Task A
Task B
Waiting task queue
Size requested by task A
Size requested by task B
Enough space is available, but
task B is blocked by task A and
cannot acquire a memory block