op_pro_parmem_access()
Abstract
Obtains the address of the memory block that is shared by the current process and its parent.
Syntax
op_pro_parmem_access ()
| Argument | Type | Description |
|---|---|---|
| no arguments |
Return Type
void*
Address of parent-to-child memory installed at time that the current process was created by its parent process. This memory address will be equal to the symbolic constant OPC_NIL when the current process is the module’s root process.
Example
/* Get the pointer to the module wide variables installed by the root process. */
mod_vars = (X25T_DTE_Mod_Vars *) op_pro_modmem_access ();
/* Get the pointer to the channel block for this channel. */
chan_vars = (X25T_Channel *) op_pro_parmem_access ();
/* Initialize channel state variables. */
chan_vars->number = chan_number;
chan_vars->process = op_pro_self ();
chan_vars->local_addr = local_addr;
chan_vars->remote_addr = remote_addr;
chan_vars->permanent = 0;
chan_vars->data_link = X25C_DTE_DL_OUTSTRM;
chan_vars->application = appl_stream;
Details
This KP allows a dynamically created process to establish a means of communicating information with its parent process. This communication is achieved by examining and modifying the contents of a shared block of memory whose format is application-specific and defined by the model developer. The KP returns the address of the [beginning of the] shared memory block, as was provided by the parent process when it called op_pro_create(). In the case where the current process is a module’s root process, this KP returns the symbolic constant OPC_NIL, since the process has no parent.
Use of the parent-to-child shared memory facility is optional and in cases where it is not used, by convention, the parent process indicates the absence of a shared-memory block by installing the symbolic constant OPC_NIL when it calls op_pro_create(). Therefore, it is generally a good practice to inspect the pointer value that is returned by op_pro_parmem_access() before dereferencing it, as a segmentation violation error will occur if the memory block is not present.
It is important that both the parent and child processes agree on the format of the shared memory so that they are consistent in their references to the information contained within it. Therefore, typically, the shared memory address that is returned by this KP is cast into an appropriate data-structure before its contents are accessed. Data structures and type definitions may be specified in the header block of process models and in include (.h) files that are incorporated by reference with the #include directive.
Purpose
This KP is intended to provide for two important mechanisms: the passing of “start-up” or initialization specifications to the child process; and the continuous exchange of information between a child process and its parent. The Simulation Kernel maintains only the address of the shared memory area that is provided when the child process is created, allowing the shared data itself to be of arbitrary format. The two processes can update and access the shared data as required by their communication protocol; updates to the data may be passive, allowing the other process to be apprised of a change only when it determines that it needs to check; or updates may be active when accompanied by asynchronous interrupts or invocations using KPs such as op_intrpt_schedule_process(), or op_pro_invoke(), respectively.
Errors
- Program Abort: KP requires process context.
Reference
- Use the KP op_pro_create() to create a child process of a specified type
- Use the KP op_intrpt_schedule_process() to schedule an interrupt for another process
- Use the KP op_pro_invoke() to cause another process to execute immediately
- Use the KP op_prg_mem_alloc() to allocate a block of dynamic memory of specifiable size