diff options
| author | rjohnson <rjohnson> | 1998-03-26 14:56:55 (GMT) | 
|---|---|---|
| committer | rjohnson <rjohnson> | 1998-03-26 14:56:55 (GMT) | 
| commit | 72d823b9193f9ee2b0318563b49363cd08c11f24 (patch) | |
| tree | c168cc164a71f320db9dcdfe7518ba7bd0d2c8d9 /unix/tclUnixEvent.c | |
| parent | 2b5738da524e944cda39e24c0a87b745a43bd8c3 (diff) | |
| download | tcl-72d823b9193f9ee2b0318563b49363cd08c11f24.zip tcl-72d823b9193f9ee2b0318563b49363cd08c11f24.tar.gz tcl-72d823b9193f9ee2b0318563b49363cd08c11f24.tar.bz2 | |
Initial revision
Diffstat (limited to 'unix/tclUnixEvent.c')
| -rw-r--r-- | unix/tclUnixEvent.c | 76 | 
1 files changed, 76 insertions, 0 deletions
| diff --git a/unix/tclUnixEvent.c b/unix/tclUnixEvent.c new file mode 100644 index 0000000..24841ca --- /dev/null +++ b/unix/tclUnixEvent.c @@ -0,0 +1,76 @@ +/*  + * tclUnixEvent.c -- + * + *	This file implements Unix specific event related routines. + * + * Copyright (c) 1997 by Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * SCCS: @(#) tclUnixEvent.c 1.1 97/03/04 14:19:34 + */ + +#include "tclInt.h" +#include "tclPort.h" + +/* + *---------------------------------------------------------------------- + * + * Tcl_Sleep -- + * + *	Delay execution for the specified number of milliseconds. + * + * Results: + *	None. + * + * Side effects: + *	Time passes. + * + *---------------------------------------------------------------------- + */ + +void +Tcl_Sleep(ms) +    int ms;			/* Number of milliseconds to sleep. */ +{ +    static struct timeval delay; +    Tcl_Time before, after; + +    /* +     * The only trick here is that select appears to return early +     * under some conditions, so we have to check to make sure that +     * the right amount of time really has elapsed.  If it's too +     * early, go back to sleep again. +     */ + +    TclpGetTime(&before); +    after = before; +    after.sec += ms/1000; +    after.usec += (ms%1000)*1000; +    if (after.usec > 1000000) { +	after.usec -= 1000000; +	after.sec += 1; +    } +    while (1) { +	delay.tv_sec = after.sec - before.sec; +	delay.tv_usec = after.usec - before.usec; +	if (delay.tv_usec < 0) { +	    delay.tv_usec += 1000000; +	    delay.tv_sec -= 1; +	} + +	/* +	 * Special note:  must convert delay.tv_sec to int before comparing +	 * to zero, since delay.tv_usec is unsigned on some platforms. +	 */ + +	if ((((int) delay.tv_sec) < 0) +		|| ((delay.tv_usec == 0) && (delay.tv_sec == 0))) { +	    break; +	} +	(void) select(0, (SELECT_MASK *) 0, (SELECT_MASK *) 0, +		(SELECT_MASK *) 0, &delay); +	TclpGetTime(&before); +    } +} | 
