srv_callback

Description

Install a state transition handler for a thread.

Syntax

CS_RETCODE srv_callback(spp, callback_type, funcp)
SRV_PROC         *spp;
CS_INT                callback_type;
CS_RETCODE     (*funcp)();

Parameters

spp

A pointer to an internal thread control structure.

callback_type

An integer that indicates the state transition for which the callback is being installed. Table 3-16 summarizes the legal values for callback_type:

Table 3-16: Values for callback_type (srv_callback)

Value

Description

SRV_C_EXIT

The thread has returned from the entry point specified in srv_spawn or is associated with a disconnected client. The handler is executed in the context of the exiting thread.

SRV_C_PROCEXEC

A registered procedure has been invoked and is about to execute. The handler executes in the context of the thread that requested the registered procedure.

SRV_C_RESUME

The thread is resuming. The handler executes in the scheduler thread’s context and uses its 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

The callback routine you install for this state transition is called when a thread has executed for a period of time (time slice) determined by the SRV_S_TIMESLICE, SRV_S_VIRTCLKRATE, and SRV_S_VIRTTIMER server properties. See srv_props and “Properties” for more information about these parameters.

funcp

A pointer to the function to call when the specified state transition occurs.

A callback function takes a thread pointer argument.

Returns

Table 3-17: Return values (srv_callback))

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#include          <stdio.h>
#include          <ospublic.h>
/*
 ** Local Prototype
 */
CS_RETCODE        suspend_handler PROTOTYPE((
SRV_PROC          *srvproc
));
CS_RETCODE ex_srv_callback PROTOTYPE((
SRV_PROC          *srvproc
));

CS_RETCODE     suspend_handler(srvproc)
SRV_PROC       *srvproc;
{
     printf(“Wake me when it’s over...\n”);
     return(CS_SUCCEED);
}

/* 
** EX_SRV_CALLBACK
**
**     Example routine to install a state transition handler.
**
** Arguments:
**   srvpro  - A pointer to an internal thread control structure.
**
** Returns:
**
**     CS_SUCCEED
**     CS_FAIL
*/
CS_RETCODE          ex_srv_callback(srvproc)
SRV_PROC            *srvproc;
{
     return(srv_callback(srvproc, SRV_C_SUSPEND,
                 suspend_handler));
}

Usage

See also

srv_capability, srv_props, srv_termproc