7.4 Variable-Sized Memory Pools
When a dynamic memory manipulation request is issued from a processing program in the RI850V4, the variable-sized memory pool is provided as a usable memory area.
Dynamic memory manipulation for variable-size memory pools is performed in the units of the specified variable-size memory block size.
7.4.1 Create variable-sized memory pool
In the RI850V4, the method of creating a variable-sized memory pool is limited to "static creation".
Variable-sized memory pools therefore cannot be created dynamically using a method such as issuing a service call from a processing program.
Static variable-size memory pool creation means defining of variable-size memory pools using static API "CRE_MPL" in the system configuration file.
7.4.2 Acquire variable-sized memory block
A variable-sized memory block is acquired (waiting forever, polling, or with timeout) by issuing the following service call from the processing program.
-
get_mpl
This service call acquires a variable-size memory block of the size (+4 byte) specified by parameter
blksz from the variable-size memory pool specified by parameter
mplid, and stores its start address into the area specified by parameter
p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory blocks but queues the invoking task to the target variable-size memory pool wait queue and moves it from the RUNNING state to the WAITING state (variable-size memory block acquisition wait state).
The WAITING state for a variable-sized memory block is cancelled in the following cases, and then moved to the READY state.
WAITING State for a Variable-sized Memory Block Cancel Operation
|
|
The variable-size memory block that satisfies the requested size was returned to the target variable-size memory pool as a result of issuing rel_mpl.
|
|
The variable-size memory block that satisfies the requested size was returned to the target variable-size memory pool as a result of issuing irel_mpl.
|
|
Forced release from waiting (accept rel_wai while waiting).
|
|
Forced release from waiting (accept irel_wai while waiting).
|
|
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/
#include <kernel_id.h> /*System information header file definition*/
void task (VP_INT exinf)
{
ER ercd; /*Declares variable*/
ID mplid = ID_MPL1; /*Declares and initializes variable*/
UINT blksz = 256; /*Declares and initializes variable*/
VP p_blk; /*Declares variable*/
.........
/*Acquire variable-sized memory block */
/*(waiting forever)*/
ercd = get_mpl (mplid, blksz, &p_blk);
if (ercd == E_OK) {
......... /*Normal termination processing*/
rel_mpl (mplid, p_blk); /*Release variable-sized memory block*/
} else if (ercd == E_RLWAI) {
......... /*Forced termination processing*/
}
.........
}
|
Note 1 The RI850V4 acquires variable-size memory blocks in the unit of "integral multiple of 4". If a value other than an integral multiple of 4 is specified for parameter
blksz, it is rounded up to be an integral multiple of 4.
Note 2 The RI850V4 needs a 4-byte area (management block) to manage the acquired variable-sized memory blocks. When this service call is issued, an area of "
blksz + 4" bytes is allocated in the target variable-sized memory pool.
Note 3 The RI850V4 does not perform memory clear processing when getting the acquired variable-size memory block. The contents of the got variable-size memory block are therefore undefined.
Note 4 Invoking tasks are queued to the target variable-size memory pool wait queue in the order defined during configuration (FIFO order or priority order).
Note 5 If the variable-size memory block acquisition wait state is cancelled because
rel_wai or
irel_wai was issued, the contents in the area specified by parameter
p_blk become undefined.
-
pget_mpl,
ipget_mpl
This service call acquires a variable-size memory block of the size (+4 byte) specified by parameter
blksz from the variable-size memory pool specified by parameter
mplid, and stores its start address into the area specified by parameter
p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory block but returns E_TMOUT.
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/
#include <kernel_id.h> /*System information header file definition*/
void task (VP_INT exinf)
{
ER ercd; /*Declares variable*/
ID mplid = ID_MTX1; /*Declares and initializes variable*/
UINT blksz = 256; /*Declares and initializes variable*/
VP p_blk; /*Declares variable*/
.........
/*Acquire variable-sized memory block*/
/*(polling)*/
ercd = pget_mpl (mplid, blksz, &p_blk);
if (ercd == E_OK) {
......... /*Polling success processing*/
rel_mpl (mplid, p_blk); /*Release variable-sized memory block*/
} else if (ercd == E_TMOUT) {
......... /*Polling failure processing*/
}
.........
}
|
Note 1 The RI850V4 acquires variable-size memory blocks in the unit of "integral multiple of 4". If a value other than an integral multiple of 4 is specified for parameter
blksz, it is rounded up to be an integral multiple of 4.
Note 2 The RI850V4 needs a 4-byte area (management block) to manage the acquired variable-sized memory blocks. When this service call is issued, an area of "
blksz + 4" bytes is allocated in the target variable-sized memory pool.
Note 3 The RI850V4 does not perform memory clear processing when getting the acquired variable-size memory block. The contents of the got variable-size memory block are therefore undefined.
Note 4 If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, the contents in the area specified by parameter
p_blk become undefined.
-
tget_mpl
This service call acquires a variable-size memory block of the size (+4 byte) specified by parameter
blksz from the variable-size memory pool specified by parameter
mplid, and stores its start address into the area specified by parameter
p_blk.
If no variable-size memory blocks could be acquired from the target variable-size memory pool (no successive areas equivalent to the requested size were available) when this service call is issued, this service call does not acquire variable-size memory blocks but queues the invoking task to the target variable-size memory pool wait queue and moves it from the RUNNING state to the WAITING state with timeout (variable-size memory block acquisition wait state).
The WAITING state for a variable-sized memory block is cancelled in the following cases, and then moved to the READY state.
WAITING State for a Variable-sized Memory Block Cancel Operation
|
|
The variable-size memory block that satisfies the requested size was returned to the target variable-size memory pool as a result of issuing rel_mpl.
|
|
The variable-size memory block that satisfies the requested size was returned to the target variable-size memory pool as a result of issuing irel_mpl.
|
|
Forced release from waiting (accept rel_wai while waiting).
|
|
Forced release from waiting (accept irel_wai while waiting).
|
|
Polling failure or timeout.
|
|
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/
#include <kernel_id.h> /*System information header file definition*/
void
task (VP_INT exinf)
{
ER ercd; /*Declares variable*/
ID mplid = ID_MPL1; /*Declares and initializes variable*/
UINT blksz = 256; /*Declares and initializes variable*/
VP p_blk; /*Declares variable*/
TMO tmout = 3600; /*Declares and initializes variable*/
.........
/*Acquire variable-sized memory block*/
/*(with timeout)*/
ercd = tget_mpl (mplid, blksz, &p_blk, tmout);
if (ercd == E_OK) {
......... /*Normal termination processing*/
rel_mpl (mplid, p_blk ; /*Release variable-sized memory block*/
} else if (ercd == E_RLWAI) {
......... /*Forced termination processing*/
} else if (ercd == E_TMOUT) {
......... /*Timeout processing*/
}
.........
}
|
Note 1 The RI850V4 acquires variable-size memory blocks in the unit of "integral multiple of 4". If a value other than an integral multiple of 4 is specified for parameter
blksz, it is rounded up to be an integral multiple of 4.
Note 2 The RI850V4 needs a 4-byte area (management block) to manage the acquired variable-sized memory blocks. When this service call is issued, an area of "
blksz + 4" bytes is allocated in the target variable-sized memory pool.
Note 3 The RI850V4 does not perform memory clear processing when getting the acquired variable-size memory block. The contents of the got variable-size memory block are therefore undefined.
Note 4 Invoking tasks are queued to the target variable-size memory pool wait queue in the order defined during configuration (FIFO order or priority order).
Note 5 If the variable-size memory block acquisition wait state is cancelled because
rel_wai or
irel_wai was issued or the wait time elapsed, the contents in the area specified by parameter
p_blk become undefined.
Note 6 TMO_FEVR is specified for wait time
tmout, processing equivalent to
get_mpl will be executed. When TMO_POL is specified, processing equivalent to
pget_mpl /
ipget_mpl will be executed.
7.4.3 Release variable-sized memory block
A variable-sized memory block is returned by issuing the following service call from the processing program.
-
rel_mpl,
irel_mpl
This service call returns the variable-sized memory block specified by parameter
blk to the variable-sized memory pool specified by parameter
mplid.
After returning the variable-size memory blocks, these service calls check the tasks queued to the target variable-size memory pool wait queue from the top, and assigns the memory if the size of memory requested by the wait queue is available. This operation continues until no tasks queued to the wait queue remain or no memory space is available. As a result, the task that acquired the memory is unlinked from the queue and moved from the WAITING state (variable-size memory block acquisition wait state) to the READY state, or from the WAITING-SUSPENDED state to the SUSPENDED state.
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/
#include <kernel_id.h> /*System information header file definition*/
void task (VP_INT exinf)
{
ER ercd; /*Declares variable*/
ID mplid = ID_MPL1; /*Declares and initializes variable*/
UINT blksz = 256; /*Declares and initializes variable*/
VP blk; /*Declares variable*/
.........
/*Acquire variable-sized memory block*/
ercd = get_mpl (mplid, blksz, &blk);
if (ercd == E_OK) {
......... /*Normal termination processing*/
rel_mpl (mplid, blk); /*Release variable-sized memory block*/
} else if (ercd == E_RLWAI) {
......... /*Forced termination processing*/
}
.........
}
|
Note 1 The RI850V4 does not perform memory clear processing when returning the acquired variable-size memory block. The contents of the returned variable-size memory block are therefore undefined.
Note 2 When returning variable-size memory blocks, be sure to issue either of these service calls for the acquired variable-size memory pools. If the service call is issued for another variable-size memory pool, no error results but the operation is not guaranteed after that.
7.4.4 Reference variable-sized memory pool state
A variable-sized memory pool status is referenced by issuing the following service call from the processing program.
-
ref_mpl,
iref_mpl
These service calls store the detailed information (ID number of the task at the head of the wait queue, total size of free memory blocks, etc.) of the variable-size memory pool specified by parameter
mplid into the area specified by parameter
pk_rmpl.
The following describes an example for coding this service call.
#include <kernel.h> /*Standard header file definition*/
#include <kernel_id.h> /*System information header file definition*/
void task (VP_INT exinf)
{
ID mplid = ID_MPL1; /*Declares and initializes variable*/
T_RMPL pk_rmpl; /*Declares data structure*/
ID wtskid; /*Declares variable*/
SIZE fmplsz; /*Declares variable*/
UINT fblksz; /*Declares variable*/
ATR mplatr; /*Declares variable*/
.........
ref_mpl (mplid, &pk_rmpl); /*Reference variable-sized memory pool state*/
wtskid = pk_rmpl.wtskid; /*Reference ID number of the task at the */
/*head of the wait queue*/
fmplsz = pk_rmpl.fmplsz; /*Reference total size of free memory blocks*/
fblksz = pk_rmpl.fblksz; /*Reference maximum memory block size*/
mplatr = pk_rmpl.mplatr; /*Reference attribute*/
.........
}
|