Modify the scheduling priority of a thread.
CS_RETCODE srv_setpri(spp, mode, priority_value)
SRV_PROC *spp; CS_INT mode; CS_INT priority_value;
A pointer to an internal thread control structure.
SRV_C_DELTAPRI, if priority_value is to adjust the current priority, or SRV_C_NEWPRI, if priority_value is the new priority.
If mode is SRV_C_NEWPRI, priority_value is the new priority for the thread. If mode is SRV_C_DELTAPRI, a negative priority_value reduces the current priority by its absolute value and a positive priority_value increases the current priority.
Returns |
To indicate |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
#include <ospublic.h>
/*
** Local Prototype.
*/
CS_RETCODE ex_srv_setpri PROTOTYPE((
SRV_PROC *spp,
CS_INT mode,
CS_INT priority
));
/*
** EX_SRV_SETPRI
**
** Example routine to change a thread’s scheduling priority.
**
** Arguments:
** spp A pointer to an internal thread control structure.
** mode Indicates whether a priority is relative or
** absolute.
** priority The change in priority value or the nrew
priority value.
**
** Returns:
**
** CS_SUCCEED
** CS_FAIL
*/
CS_RETCODE ex_srv_setpri(spp, mode, priority)
SRV_PROC *spp;
CS_INT mode;
CS_INT priority;
{
return(srv_setpri(spp, mode, priority));
}
When a thread is started as the result of a client logging into the Open Server or as the result of a call to srv_createproc or srv_spawn, it has a priority of SRV_C_DEFAULTPRI.
srv_setpri can change the priority by specifying the new value or by adjusting the current value up or down by a specified value.
If a thread sets the priority of another thread to a level higher than its own, the other thread is scheduled to run immediately. Otherwise, the new priority of the affected thread takes effect the next time the scheduler runs.
If a thread that never sleeps has a priority higher than other threads, the lower priority threads will never have a chance to execute.
Internal Open Server threads run with a priority of SRV_C_DEFAULTPRI. If you raise the priority of a thread above SRV_C_DEFAULTPRI, it must sleep occasionally to allow these internal processes to run.
It is an error to reduce the priority to less than SRV_C_LOWPRIORITY or to increase it to a value greater than SRV_C_MAXPRIORITY.
srv_setpri cannot be used in a SRV_START handler.