sl@0: /* sl@0: * tclUnixEvent.c -- sl@0: * sl@0: * This file implements Unix specific event related routines. sl@0: * sl@0: * Copyright (c) 1997 by Sun Microsystems, Inc. sl@0: * Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved. sl@0: * sl@0: * See the file "license.terms" for information on usage and redistribution sl@0: * of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: * sl@0: * RCS: @(#) $Id: tclUnixEvent.c,v 1.4 2001/11/21 02:36:21 hobbs Exp $ sl@0: */ sl@0: sl@0: #include "tclInt.h" sl@0: #include "tclPort.h" sl@0: /* sl@0: *---------------------------------------------------------------------- sl@0: * sl@0: * Tcl_Sleep -- sl@0: * sl@0: * Delay execution for the specified number of milliseconds. sl@0: * sl@0: * Results: sl@0: * None. sl@0: * sl@0: * Side effects: sl@0: * Time passes. sl@0: * sl@0: *---------------------------------------------------------------------- sl@0: */ sl@0: sl@0: EXPORT_C void sl@0: Tcl_Sleep(ms) sl@0: int ms; /* Number of milliseconds to sleep. */ sl@0: { sl@0: struct timeval delay; sl@0: Tcl_Time before, after; sl@0: sl@0: /* sl@0: * The only trick here is that select appears to return early sl@0: * under some conditions, so we have to check to make sure that sl@0: * the right amount of time really has elapsed. If it's too sl@0: * early, go back to sleep again. sl@0: */ sl@0: sl@0: Tcl_GetTime(&before); sl@0: after = before; sl@0: after.sec += ms/1000; sl@0: after.usec += (ms%1000)*1000; sl@0: if (after.usec > 1000000) { sl@0: after.usec -= 1000000; sl@0: after.sec += 1; sl@0: } sl@0: while (1) { sl@0: delay.tv_sec = after.sec - before.sec; sl@0: delay.tv_usec = after.usec - before.usec; sl@0: if (delay.tv_usec < 0) { sl@0: delay.tv_usec += 1000000; sl@0: delay.tv_sec -= 1; sl@0: } sl@0: sl@0: /* sl@0: * Special note: must convert delay.tv_sec to int before comparing sl@0: * to zero, since delay.tv_usec is unsigned on some platforms. sl@0: */ sl@0: sl@0: if ((((int) delay.tv_sec) < 0) sl@0: || ((delay.tv_usec == 0) && (delay.tv_sec == 0))) { sl@0: break; sl@0: } sl@0: #ifdef __SYMBIAN32__ sl@0: (void) select(0, NULL, NULL, sl@0: NULL, &delay); sl@0: #else sl@0: (void) select(0, (SELECT_MASK *) 0, (SELECT_MASK *) 0, sl@0: (SELECT_MASK *) 0, &delay);*/ sl@0: #endif sl@0: Tcl_GetTime(&before); sl@0: } sl@0: }