os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclUnixEvent.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* 
sl@0
     2
 * tclUnixEvent.c --
sl@0
     3
 *
sl@0
     4
 *	This file implements Unix specific event related routines.
sl@0
     5
 *
sl@0
     6
 * Copyright (c) 1997 by Sun Microsystems, Inc.
sl@0
     7
 * Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved.  
sl@0
     8
 *
sl@0
     9
 * See the file "license.terms" for information on usage and redistribution
sl@0
    10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    11
 *
sl@0
    12
 * RCS: @(#) $Id: tclUnixEvent.c,v 1.4 2001/11/21 02:36:21 hobbs Exp $
sl@0
    13
 */
sl@0
    14
sl@0
    15
#include "tclInt.h"
sl@0
    16
#include "tclPort.h"
sl@0
    17
/*
sl@0
    18
 *----------------------------------------------------------------------
sl@0
    19
 *
sl@0
    20
 * Tcl_Sleep --
sl@0
    21
 *
sl@0
    22
 *	Delay execution for the specified number of milliseconds.
sl@0
    23
 *
sl@0
    24
 * Results:
sl@0
    25
 *	None.
sl@0
    26
 *
sl@0
    27
 * Side effects:
sl@0
    28
 *	Time passes.
sl@0
    29
 *
sl@0
    30
 *----------------------------------------------------------------------
sl@0
    31
 */
sl@0
    32
sl@0
    33
EXPORT_C void
sl@0
    34
Tcl_Sleep(ms)
sl@0
    35
    int ms;			/* Number of milliseconds to sleep. */
sl@0
    36
{
sl@0
    37
    struct timeval delay;
sl@0
    38
    Tcl_Time before, after;
sl@0
    39
sl@0
    40
    /*
sl@0
    41
     * The only trick here is that select appears to return early
sl@0
    42
     * under some conditions, so we have to check to make sure that
sl@0
    43
     * the right amount of time really has elapsed.  If it's too
sl@0
    44
     * early, go back to sleep again.
sl@0
    45
     */
sl@0
    46
sl@0
    47
    Tcl_GetTime(&before);
sl@0
    48
    after = before;
sl@0
    49
    after.sec += ms/1000;
sl@0
    50
    after.usec += (ms%1000)*1000;
sl@0
    51
    if (after.usec > 1000000) {
sl@0
    52
	after.usec -= 1000000;
sl@0
    53
	after.sec += 1;
sl@0
    54
    }
sl@0
    55
    while (1) {
sl@0
    56
	delay.tv_sec = after.sec - before.sec;
sl@0
    57
	delay.tv_usec = after.usec - before.usec;
sl@0
    58
	if (delay.tv_usec < 0) {
sl@0
    59
	    delay.tv_usec += 1000000;
sl@0
    60
	    delay.tv_sec -= 1;
sl@0
    61
	}
sl@0
    62
sl@0
    63
	/*
sl@0
    64
	 * Special note:  must convert delay.tv_sec to int before comparing
sl@0
    65
	 * to zero, since delay.tv_usec is unsigned on some platforms.
sl@0
    66
	 */
sl@0
    67
sl@0
    68
	if ((((int) delay.tv_sec) < 0)
sl@0
    69
		|| ((delay.tv_usec == 0) && (delay.tv_sec == 0))) {
sl@0
    70
	    break;
sl@0
    71
	}
sl@0
    72
#ifdef __SYMBIAN32__  	
sl@0
    73
	(void) select(0, NULL, NULL,
sl@0
    74
		NULL, &delay);
sl@0
    75
#else
sl@0
    76
	(void) select(0, (SELECT_MASK *) 0, (SELECT_MASK *) 0,
sl@0
    77
		(SELECT_MASK *) 0, &delay);*/
sl@0
    78
#endif
sl@0
    79
	Tcl_GetTime(&before);
sl@0
    80
    }
sl@0
    81
}