Communicating with Event States
Event states offer an alternative and faster method of associating data with an event than do ICIs. An event state is an arbitrary user-defined data structure that can be installed and thereafter is associated automatically with each generated event until a new event state is installed. Event states can be used for the same purposes as ICIs (see Applications of ICIs for a discussion of these).
Event states provide better performance than ICIs because there is no need to use a KP such as op_ici_attr_get_dbl() to access an object structure (which is computationally expensive). Instead, you can create an arbitrary data structure and access the structure fields with standard C/C++ operators. As with ICIs, you are fully responsible for properly deallocating the event state when no longer needed.
Note: Because the Simulation Kernel does not know anything about the content of an event state, you must be sure you are getting and setting event states of the correct data type.
Three KPs support operations on event states. The capabilities provided by these KPs are listed in the following table. Detailed explanations of each KP are provided in Discrete Event Simulation API.
Table 101: Event State-Related Kernel Procedures
| Kernel Procedure | Provided Capability |
|---|---|
op_ev_state_install() |
Installs an event state to be associated with all events created in the same thread. |
op_ev_state() |
Gets the event state previously associated with an event. |
op_intrpt_state_ptr_get() |
Gets the client state associated with the current event. |
In the parallel kernel, each execution thread has its own global state that can be attached to events. Therefore, the value of an installed event state is only valid for the duration of current interrupt processing and might be overwritten or cleared when execution is transferred to a different module via op_pro_invoke(), op_ev_send_forced(), or other mechanisms.