⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 starsleep.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
#ifndef lintstatic	char	*sccsid = "@(#)starsleep.c	4.1	(ULTRIX)	11/23/87";#endif lint/************************************************************************ *									* *			Copyright (c) 1985 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************/* * starsleep.c * * Name:	starsleep * Purpose:	sleep routine with microseconds added, to enable sleeping *		for a fraction of a second. * Usage:	starsleep(secs, usecs) * Environment:	Ultrix-32 * Compile:	see Makefile * Date:	November 19, 1985 * Author:	Al Delorey * Remarks: *//* * Modification history: * * November 19, 1985 - afd *	Derived from Berkeley 4.2 sleep routine. */#include <sys/time.h>#include <signal.h>#define	mask(s)	(1<<((s)-1))#define	setvec(vec, a) \	vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0static int ringring;starsleep(n,usecs)	unsigned n;		/* number of seconds */	unsigned usecs;		/* usecs */{	int sleepx(), omask;	struct itimerval itv, oitv;	register struct itimerval *itp = &itv;	struct sigvec vec, ovec;	if (n == 0 && usecs == 0)		return;	timerclear(&itp->it_interval);	timerclear(&itp->it_value);	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)		return;	setvec(ovec, SIG_DFL);	omask = sigblock(0);	/* Assign seconds and micro seconds */	itp->it_value.tv_sec = n;	itp->it_value.tv_usec = usecs;	if (timerisset(&oitv.it_value)) {		if (timercmp(&oitv.it_value, &itp->it_value, >))			oitv.it_value.tv_sec -= itp->it_value.tv_sec;		else {			itp->it_value = oitv.it_value;			/*			 * This is a hack, but we must have time to			 * return from the setitimer after the alarm			 * or else it'll be restarted.  And, anyway,			 * sleep never did anything more than this before.			 */			oitv.it_value.tv_sec = 1;			oitv.it_value.tv_usec = 0;		}	}	setvec(vec, sleepx);	(void) sigvec(SIGALRM, &vec, &ovec);	ringring = 0;	(void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);	while (!ringring)		sigpause(omask &~ mask(SIGALRM));	(void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);	(void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0);}staticsleepx(){	ringring = 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -