1
/* knocker version 0.7.1
2
* Release date: 24 May 2002
4
* Project homepage: http://knocker.sourceforge.net
6
* Copyright 2001,2002 Gabriele Giorgetti <g.gabriele79@genie.it>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
#include "knocker_time.h"
35
#endif /* __WIN32__ */
38
static unsigned long timer_start;
40
static struct timeval timer_start;
44
void knocker_time_start_timer (void)
47
timer_start = GetTickCount ();
49
/* Set first ticks value */
50
gettimeofday (&timer_start, NULL);
54
double knocker_time_get_ticks (void)
59
na timer_now = GetTickCount ();
60
ticks = ((timer_now - timer_start));
63
struct timeval timer_now;
65
gettimeofday (&timer_now, NULL);
66
ticks = (timer_now.tv_sec - timer_start.tv_sec) * 1000 + (timer_now.tv_usec - timer_start.tv_usec) / 1000;
72
void knocker_time_delay (unsigned long ms)
79
/* #if defined (HAVE_PAUSE) && defined (HAVE_NANOSLEEP) */
82
# ifdef HAVE_NANOSLEEP
83
--------------------- UNTESTED !!!!!!! --------------------------
90
rqtp.tv_sec = (time_t) pause / 1000;
92
rqtp.tv_nsec = (long) (pause % 1000) * 1000000;
94
(void) nanosleep (&rqtp, NULL);
103
before = knocker_time_get_ticks ();
107
fprintf (stderr, "debug: function knocker_time_delay() called.\n");
108
fprintf (stderr, "debug: timer is now = %f (it should be 0)\n", now);
109
fprintf (stderr, "debug: delaying for %f milliseconds...", ms);
112
/* Very bad do nothing delay loop */
115
now = knocker_time_get_ticks ();
117
if (now > before + ms)
118
break; /* just to make sure we don't get stuck in this loop */
119
/* if the test now <= before + ms fails */
122
while (now <= before + ms);
128
fprintf (stderr, " done.\n");
129
fprintf (stderr, "debug: timer is now = %f \n", now);
132
#endif /* ifdef __WIN32__ */