CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

timetag.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2004 Steve Harris
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * $Id$
15 */
16
17 #include "lo_types_internal.h"
18 #include "lo/lo.h"
19
20 #ifdef _MSC_VER
21 lo_timetag lo_get_tt_immediate() { lo_timetag tt = {0U,1U}; return tt; }
22 #else
23 #include <sys/time.h>
24 #endif
25 #include <time.h>
26
27 #define JAN_1970 0x83aa7e80 /* 2208988800 1970 - 1900 in seconds */
28
29 double lo_timetag_diff(lo_timetag a, lo_timetag b)
30 {
31 return (double)a.sec - (double)b.sec +
32 ((double)a.frac - (double)b.frac) * 0.00000000023283064365;
33 }
34
35 void lo_timetag_now(lo_timetag *t)
36 {
37 #ifdef WIN32
38 /*
39 FILETIME is the time in units of 100 nsecs from 1601-Jan-01
40 1601 and 1900 are 9435484800 seconds apart.
41 */
42 FILETIME ftime;
43 double dtime;
44 GetSystemTimeAsFileTime(&ftime);
45 dtime =
46 ((ftime.dwHighDateTime*4294967296.e-7)-9435484800.)+
47 (ftime.dwLowDateTime*1.e-7);
48
49 t->sec = (uint32_t)dtime;
50 t->frac = (uint32_t)((dtime-t->sec)*4294967296.);
51 #else
52 struct timeval tv;
53
54 gettimeofday(&tv, NULL);
55 t->sec = tv.tv_sec + JAN_1970;
56 t->frac = tv.tv_usec * 4294.967295;
57 #endif
58 }