delay(9F)
NAME
delay − delay process execution for a specified number of clock ticks
SYNOPSIS
#include <sys/ddi.h>
void delay(long ticks);
ARGUMENTS
ticks The number of clock cycles for a delay. ticks are frequently set as an expression containing the system variable HZ, the number of clock ticks in one second; HZ is defined in <sys/param.h>.
INTERFACE LEVEL
Architecture independent level 1 (DDI/DKI).
DESCRIPTION
delay() provides a mechanism for a driver to delay its execution for a given period of time. The value of HZ can vary from system to system, and so the function drv_usectohz(9F) should be used when accurate timing is required.
delay() uses timeout(9F) to schedule a wakeup event after the specified amount of time has elapsed. delay() then goes to sleep until timeout() wakes up the caller.
CONTEXT
delay() can be called from user context only.
EXAMPLE
Before a driver I/O routine allocates buffers and stores any user data in them, it checks the status of the device (line 12). If the device needs manual intervention (such as, needing to be refilled with paper), a message is displayed on the system console (line 14). The driver waits an allotted time (line 16) before repeating the procedure.
1 struct device {/∗ layout of physical device registers ∗/
2 int control;/∗ physical device control word ∗/
3 int status;/∗ physical device status word ∗/
4 short xmit_char;/∗ transmit character to device ∗/
5 };/∗ end device ∗/
6
7 extern struct device ∗xx_addr;/∗ physical device registers location ∗/
. . .
9/∗ get device registers ∗/
10 register struct device ∗rp = ...
11
12 while (rp->status & NOPAPER) { /∗ while printer is out of paper ∗/
13/∗ display message and ring bell on system console ∗/
14 cmn_err(CE_WARN, "^xx_write: NO PAPER in printer %d\007",
15 (getminor(dev) & 0xf));
16 delay(60 ∗ HZ);/∗ wait one minute and try again ∗/
17 }/∗ endwhile ∗/
SEE ALSO
biodone(9F), biowait(9F), drv_hztousec(9F), drv_usectohz(9F), timeout(9F), untimeout(9F), drv_usecwait(9F)
SunOS 5.1 Writing Device Drivers
SunOS 5.1 — Last change: 18 Sep 1992