srv_sleep

Description

Suspend the currently executing thread.

Syntax

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;

Parameters

sleepeventp

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.

sleeplabelp

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.

sleepflags

The value of this flag determines the manner in which the thread will wake up. Table 3-130 summarizes the legal values for sleepflags:

Table 3-130:  Values for sleepflags (srv_sleep)

Value

Description

SRV_M_ATTNWAKE

The thread wakes up if it receives an attention.

SRV_M_NOATTNWAKE

Attentions cannot wake up the thread.

infop

A pointer to a CS_INT. Table 3-131 describes the possible values returned in *infop if srv_sleep returns CS_FAIL:

Table 3-131:  Values for infop (srv_sleep)

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.

reserved1

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.

reserved2

This parameter is not currently used. Set it to 0.

Returns

Table 3-132:  Return values (srv_sleep)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#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));
}

Usage

See also

srv_wakeup