diff options
Diffstat (limited to 'unix/tclUnixEvent.c')
| -rw-r--r-- | unix/tclUnixEvent.c | 63 | 
1 files changed, 41 insertions, 22 deletions
| diff --git a/unix/tclUnixEvent.c b/unix/tclUnixEvent.c index 00371b5..40aac6f 100644 --- a/unix/tclUnixEvent.c +++ b/unix/tclUnixEvent.c @@ -1,18 +1,17 @@ -/*  +/*   * 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. - * - * RCS: @(#) $Id: tclUnixEvent.c,v 1.3 1999/04/16 00:48:04 stanton Exp $ + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES.   */  #include "tclInt.h" -#include "tclPort.h" +#ifndef HAVE_COREFOUNDATION	/* Darwin/Mac OS X CoreFoundation notifier is +				 * in tclMacOSXNotify.c */  /*   *---------------------------------------------------------------------- @@ -31,20 +30,19 @@   */  void -Tcl_Sleep(ms) -    int ms;			/* Number of milliseconds to sleep. */ +Tcl_Sleep( +    int ms)			/* Number of milliseconds to sleep. */  {      struct timeval delay; -    Tcl_Time before, after; +    Tcl_Time before, after, vdelay;      /* -     * 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. +     * 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); +    Tcl_GetTime(&before);      after = before;      after.sec += ms/1000;      after.usec += (ms%1000)*1000; @@ -53,16 +51,28 @@ Tcl_Sleep(ms)  	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; +	/* +	 * TIP #233: Scale from virtual time to real-time for select. +	 */ + +	vdelay.sec  = after.sec  - before.sec; +	vdelay.usec = after.usec - before.usec; + +	if (vdelay.usec < 0) { +	    vdelay.usec += 1000000; +	    vdelay.sec  -= 1;  	} +	if ((vdelay.sec != 0) || (vdelay.usec != 0)) { +	    tclScaleTimeProcPtr(&vdelay, tclTimeClientData); +	} + +	delay.tv_sec  = vdelay.sec; +	delay.tv_usec = vdelay.usec; +  	/* -	 * Special note:  must convert delay.tv_sec to int before comparing -	 * to zero, since delay.tv_usec is unsigned on some platforms. +	 * 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) @@ -71,6 +81,15 @@ Tcl_Sleep(ms)  	}  	(void) select(0, (SELECT_MASK *) 0, (SELECT_MASK *) 0,  		(SELECT_MASK *) 0, &delay); -	TclpGetTime(&before); +	Tcl_GetTime(&before);      }  } + +#endif /* HAVE_COREFOUNDATION */ +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ | 
