blob: 35c69baece6e2ab59046fd0b480879a2c00b0b32 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*
* Portable timer implementation for Darwin / MacOS X
*
* Jon Parise <jparise@cmu.edu>
*
* $Id: ptdarwin.c,v 1.6 2004-11-11 04:58:20 millerpuckette Exp $
*/
#include <stdio.h>
#include <sys/time.h>
#include "porttime.h"
#define TRUE 1
#define FALSE 0
static int time_started_flag = FALSE;
static struct timeval time_offset;
PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
{
struct timezone tz;
if (callback) printf("error in porttime: callbacks not implemented\n");
time_started_flag = TRUE;
gettimeofday(&time_offset, &tz);
return ptNoError;
}
PtError Pt_Stop(void) // xjs added void
{
time_started_flag = FALSE;
return ptNoError;
}
int Pt_Started(void) // xjs added void
{
return time_started_flag;
}
PtTimestamp Pt_Time(void *time_info) // xjs added void *time_info
{
long seconds, milliseconds;
struct timeval now;
struct timezone tz;
gettimeofday(&now, &tz);
seconds = now.tv_sec - time_offset.tv_sec;
milliseconds = (now.tv_usec - time_offset.tv_usec) / 1000;
return (seconds * 1000 + milliseconds);
}
|