3311
|
1 /* |
|
2 |
|
3 Copyright (C) 1999 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_UNISTD_H |
|
28 #ifdef HAVE_SYS_TYPES_H |
|
29 #include <sys/types.h> |
|
30 #endif |
|
31 #include <unistd.h> |
|
32 #endif |
|
33 |
|
34 #include "systime.h" |
|
35 |
|
36 #ifdef HAVE_POLL_H |
|
37 #include <poll.h> |
|
38 #elif HAVE_SYS_POLL_H |
|
39 #include <sys/poll.h> |
|
40 #endif |
|
41 |
3317
|
42 static void |
|
43 do_octave_usleep (unsigned int useconds) |
3311
|
44 { |
|
45 #if defined (HAVE_USLEEP) |
|
46 |
|
47 usleep (useconds); |
|
48 |
|
49 #elif defined (HAVE_SELECT) |
|
50 |
|
51 struct timeval delay; |
|
52 |
|
53 delay.tv_sec = 0; |
|
54 delay.tv_usec = useconds; |
|
55 |
|
56 select (0, 0, 0, 0, &delay); |
|
57 |
|
58 #elif defined (HAVE_POLL) |
|
59 |
|
60 struct pollfd pfd; |
|
61 int delay = useconds / 1000; |
|
62 |
3317
|
63 if (delay > 0) |
|
64 poll (&fd, 0, delay); |
3311
|
65 |
|
66 #endif |
|
67 } |
|
68 |
3317
|
69 void |
|
70 octave_usleep (unsigned int useconds) |
|
71 { |
|
72 unsigned int sec = useconds / 1000000; |
|
73 unsigned int usec = useconds % 1000000; |
|
74 |
|
75 if (sec > 0) |
|
76 sleep (sec); |
|
77 |
|
78 do_usleep (usec); |
|
79 } |
|
80 |
3311
|
81 /* |
|
82 ;;; Local Variables: *** |
|
83 ;;; mode: C++ *** |
|
84 ;;; End: *** |
|
85 */ |