op_intrpt_schedule_call_mt()
Abstract
Schedules an invocation of the specified procedure, at the specified time (mutex safe).
Syntax
op_intrpt_schedule_call_mt (time, code, procedure, state_ptr)
| Argument | Type | Description |
|---|---|---|
time |
double |
scheduled time for the interrupt [This value is an absolute simulation time or a constant from Table 58 “Interrupt Time Symbolic Constants“ on page 15.] |
code |
int |
user-defined numeric code that is passed to the called procedure [This value is an arbitrary, user-defined integer that can be used as an identification code for the scheduled call. You can assign a text string that will be printed along with this code when it appears in ODB event banners and traces. See “Interrupt Code Map“ on page 507 for details.] |
procedure |
SimT_Intrpt_Callback_MT |
procedure that is to be called by the scheduled event [This value must be a pointer to a C function that takes two or (in parallel simulations) three arguments (the simulation context, state memory pointer, and integer code) and performs the desired simulation task.] |
state_ptr |
void* |
pointer to a data structure (or simple variable) that is passed to the called procedure |
Return Type
Evhandle
Event handle for the scheduled interrupt.
[This returned value can be stored in a state variable, for possible later use to identify the interrupt in an invocation of op_ev_cancel().]
Example
static void
c3sim_pos_animate (OP_SIM_CONTEXT_ARG_OPT_COMMA void * v_state_ptr, int code)
{
struct Pos_DS *ndp_ds_ptr = (struct Pos_DS *) v_state_ptr;
FIN_MT (c3sim_pos_animate);
gfx_package_node_plot (ndp_ds_ptr->lat, ndp_ds_ptr->long, ndp_ds_ptr->alt);
FOUT;
}
void
c3sim_sched_pos_animation (int ntimes, double sim_duration)
{
double d, anim_int;
static struct Pos_DS node_ps_ds = {0, 0, 0};
FIN (c3sim_sched_pos_animation);
anim_int = sim_duration / ntimes;
for (d = 0.0; d < sim_duration; d += anim_int)
op_intrpt_schedule_call_mt (d, 0, c3sim_pos_animate, &node_pos_ds);
FOUT;
}
Details
This function works like op_intrpt_schedule_call(), except that it is mutex safe and can be used in parallel simulations.
Purpose
Provides a mutex-safe mechanism for causing an arbitrary, user-written procedure to be scheduled and called at a specified simulation time in a parallel simulation. This is a convenient way of time-sequencing activities without having a dedicated process model handle interrupt trapping and procedure calling duties. Typically this KP is used to interface simulations with external libraries or user-written simulation procedures.
Errors
- Program Abort: Allocation of memory failed.
- Recoverable Error: Specified time (
<time>) is less than current time. - Recoverable Error: Specified time (
<time>) is an invalid double value.
Reference
- Use the KP op_intrpt_schedule_call() to schedule a procedure invocation in non-parallel simulations
- Use the KP op_intrpt_schedule_self() to schedule a self interrupt
- Use the KP op_intrpt_schedule_remote() to schedule a remote interrupt
- Use the KP op_intrpt_force_remote() to force a remote interrupt
- Use the KP op_ev_cancel() to cancel a pending interrupt