Callback routines

The srv_callback routine allows you to install a callback handler for a thread. Open Server calls your routine whenever the state of the thread changes to the state you specify. For example, you can install a SRV_C_SUSPEND callback handler that executes whenever the thread is suspended.

NoteThe ability to install and execute callback handlers is platform-dependent. Use srv_capability to find out if a callback handler can be installed for a particular state transition on your current platform.

Table 2-23 summarizes the state transitions for which srv_callback can install callback handlers:

Table 2-23: State transitions

State transition

Meaning

SRV_C_EXIT

The thread has finished executing the routine it was spawned to execute, or it is associated with a disconnected client. The handler executes in the context of the exiting thread.

SRV_C_PROCEXEC

Open Server calls this callback when a registered procedure is about to execute. The handler executes in the context of the thread that requested the registered procedure. As a result, the SRV_C_PROCEXEC callback handler executes whenever a client attempts any registered procedure operation. You can install a callback handler that restricts clients’ abilities to create, delete, or execute registered procedures.

SRV_C_RESUME

The thread is resuming. The handler executes in the context of the scheduler thread and uses the scheduler’s stack.

SRV_C_SUSPEND

The thread is suspending. The handler executes in the context of the thread that is suspending and uses its stack.

SRV_C_TIMESLICE

A thread has executed for a period of time (time slice) determined by the SRV_TIMESLICE, SRV_VIRTCLKRATE, and SRV_VIRTTIMER configuration parameters. You can use this handler to signal a long-running thread to call srv_yield so that other threads can run.