Debian Codegraph @

pTk/mTk/tclUnix/tclUnixEvent.c

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