os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclUnixEvent.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclUnixEvent.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,81 @@
     1.4 +/* 
     1.5 + * tclUnixEvent.c --
     1.6 + *
     1.7 + *	This file implements Unix specific event related routines.
     1.8 + *
     1.9 + * Copyright (c) 1997 by Sun Microsystems, Inc.
    1.10 + * Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved.  
    1.11 + *
    1.12 + * See the file "license.terms" for information on usage and redistribution
    1.13 + * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    1.14 + *
    1.15 + * RCS: @(#) $Id: tclUnixEvent.c,v 1.4 2001/11/21 02:36:21 hobbs Exp $
    1.16 + */
    1.17 +
    1.18 +#include "tclInt.h"
    1.19 +#include "tclPort.h"
    1.20 +/*
    1.21 + *----------------------------------------------------------------------
    1.22 + *
    1.23 + * Tcl_Sleep --
    1.24 + *
    1.25 + *	Delay execution for the specified number of milliseconds.
    1.26 + *
    1.27 + * Results:
    1.28 + *	None.
    1.29 + *
    1.30 + * Side effects:
    1.31 + *	Time passes.
    1.32 + *
    1.33 + *----------------------------------------------------------------------
    1.34 + */
    1.35 +
    1.36 +EXPORT_C void
    1.37 +Tcl_Sleep(ms)
    1.38 +    int ms;			/* Number of milliseconds to sleep. */
    1.39 +{
    1.40 +    struct timeval delay;
    1.41 +    Tcl_Time before, after;
    1.42 +
    1.43 +    /*
    1.44 +     * The only trick here is that select appears to return early
    1.45 +     * under some conditions, so we have to check to make sure that
    1.46 +     * the right amount of time really has elapsed.  If it's too
    1.47 +     * early, go back to sleep again.
    1.48 +     */
    1.49 +
    1.50 +    Tcl_GetTime(&before);
    1.51 +    after = before;
    1.52 +    after.sec += ms/1000;
    1.53 +    after.usec += (ms%1000)*1000;
    1.54 +    if (after.usec > 1000000) {
    1.55 +	after.usec -= 1000000;
    1.56 +	after.sec += 1;
    1.57 +    }
    1.58 +    while (1) {
    1.59 +	delay.tv_sec = after.sec - before.sec;
    1.60 +	delay.tv_usec = after.usec - before.usec;
    1.61 +	if (delay.tv_usec < 0) {
    1.62 +	    delay.tv_usec += 1000000;
    1.63 +	    delay.tv_sec -= 1;
    1.64 +	}
    1.65 +
    1.66 +	/*
    1.67 +	 * Special note:  must convert delay.tv_sec to int before comparing
    1.68 +	 * to zero, since delay.tv_usec is unsigned on some platforms.
    1.69 +	 */
    1.70 +
    1.71 +	if ((((int) delay.tv_sec) < 0)
    1.72 +		|| ((delay.tv_usec == 0) && (delay.tv_sec == 0))) {
    1.73 +	    break;
    1.74 +	}
    1.75 +#ifdef __SYMBIAN32__  	
    1.76 +	(void) select(0, NULL, NULL,
    1.77 +		NULL, &delay);
    1.78 +#else
    1.79 +	(void) select(0, (SELECT_MASK *) 0, (SELECT_MASK *) 0,
    1.80 +		(SELECT_MASK *) 0, &delay);*/
    1.81 +#endif
    1.82 +	Tcl_GetTime(&before);
    1.83 +    }
    1.84 +}