Suspend the currently executing thread.
CS_RETCODE srv_sleep(sleepeventp, sleeplabelp, sleepflags, infop, reserved1, reserved2)
CS_VOID *sleepeventp; CS_CHAR *sleeplabelp; CS_INT sleepflags; CS_INT *infop; CS_VOID *reserved1; CS_VOID *reserved2;
A generic void pointer that srv_wakeup uses to wake up the thread or threads. The pointer should be unique for the operating system event the threads are sleeping on. For example, if a message is passed to another thread, the sending thread could sleep until the message was processed. The pointer to the message would be a useful sleepevent that the receiving thread could pass to srv_wakeup to wake up the sender.
A pointer to a null terminated character string that identifies the event that the thread is sleeping on. This is useful for determining why a thread is sleeping. An application can display this information using the Open Server system registered procedure sp_ps.
The value of this flag determines the manner in which the thread will wake up. Table 3-133 summarizes the legal values for sleepflags:
Value |
Description |
---|---|
SRV_M_ATTNWAKE |
The thread wakes up if it receives an attention. |
SRV_M_NOATTNWAKE |
Attentions cannot wake up the thread. |
A pointer to a CS_INT. Table 3-134 describes the possible values returned in *infop if srv_sleep returns CS_FAIL:
Value |
Description |
---|---|
SRV_I_INTERRUPTED |
The thread was woken unconditionally by srv_ucwakeup. |
SRV_I_UNKNOWN |
Some other error occurred. For example, the thread is al&ready sleeping or is invalid. |
A platform-dependent handle to a mutex. This argument is ignored on non-preemptive platforms. Set it to (CS_VOID*)0 on non-preemptive platforms.
This parameter is not currently used. Set it to 0.
Returns |
To indicate |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
#include <ospublic.h>
/*
** Local Prototype.
*/
CS_RETCODE ex_srv_sleep PROTOTYPE((
CS_VOID *sleepevnt,
CS_CHAR *sleeplbl,
CS_INT *infop
));
/*
** EX_SRV_SLEEP
**
** This routine will suspend the currently executing thread.
**
**
** Arguments:
**
**
** sleepevnt A void pointer that srv_wakeup uses to wake up
** the thread.
** sleeplbl A pointer to a null terminated string that
** identifies the event being the thread is sleeping
** on. This is primarily used for debugging.
** infop A pointer to a CS_INT that is set to one of the
** following values:
** SRV_I_INTERRUPTED - srv_ucwakeup
** unconditionally woke the thread.
** SRV_I_UNKNOWN - Some other error occurred.
**
**
** Returns
**
** CS_SUCCEED
** CS_FAIL
**
*/
CS_RETCODE ex_srv_sleep(sleepevnt,sleeplbl,infop)
CS_VOID *sleepevnt;
CS_CHAR *sleeplbl;
CS_INT *infop;
{
/* Check arguments. */
if(sleepevnt == (CS_VOID *)NULL)
{
return(CS_FAIL);
}
/*
** Using SRV_M_ATTNWAKE means the thread should wake up
** unconditionally if it receives an attention.
*/
return(srv_sleep(sleepevnt,sleeplbl,SRV_M_ATTNWAKE,infop,(CS_VOID*)0,(CS_VOID*)0));
}
srv_sleep suspends the currently executing thread and initiates rescheduling. The thread will sleep until srv_wakeup is called on the same event.
Depending on the value of sleepflags, a thread that is sleeping can also wake up by receiving an attention.
A thread resumes execution on the statement just following the call to srv_sleep.
srv_sleep cannot be used in a SRV_START handler.
srv_sleep should not be called from interrupt level code. Any number of problems could occur if this rule is violated.
Call srv_capability to determine whether your platform supports preemptive scheduling.
The reserved1 parameter prevents a race condition that could occur with preemptive scheduling if the wakeup event occurred before the thread finished going to sleep. See the Open Client and Open Server Programmers Supplement for your platform for an example of preemptive scheduling.