annotate future.c @ 88:9b7588cd4013

Move data acquisition into separate thread The data acquisition thread transfers data to the main thread trough a Thread Safe Queue. This separation allows for making the data acquisition system pluggable. The old file based communication to the KK counter is implemented along with a very simple fake data provider.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 21 Mar 2013 18:24:45 +0100
parents be814b934eca
children 4102fe614df2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 /* welcome in the 2012 */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 /* required by CVI */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include <ansi_c.h>
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5
81
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
6 /* time functions */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
7 #include <windows.h>
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
8
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
9 #include "future.h"
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
10
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
11
16
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12 /* an implementation of the C99 `round` function based on `floor` and `ceil` */
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 double round(double x)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 if (x >= 0.0) {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16 double y = floor(x);
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 if (x - y >= 0.5)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 y += 1.0;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19 return y;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 } else {
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
21 double y = ceil(x);
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22 if (x - y >= 0.5)
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
23 y -= 1.0;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 return y;
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 }
9d57d1fcbcd5 Implementation of the C99 round() function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 }
81
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
27
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
28
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
29 /* implement high resolution time service */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
30 int gettimeofday(struct timeval *tp, struct timezone *tzp)
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
31 {
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
32 /* difference between 1970-01-01 and 1601-01-01
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
33 in 100-nanoseconds intervals */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
34 const unsigned __int64 shift = 116444736000000000ULL;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
35 union {
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
36 FILETIME ft;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
37 unsigned __int64 integer; /* 100-nanoseconds since 1601-01-01 */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
38 } now;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
39
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
40 /* retrive system time in UTC. the resolution is limited to the resolution
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
41 of the system timer, which is typically in the range of 10 milliseconds
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
42 to 16 milliseconds */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
43 GetSystemTimeAsFileTime(&now.ft);
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
44
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
45 /* shift to epoch and truncate to microseconds */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
46 now.integer = (now.integer - shift) / 10LL;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
47
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
48 tp->tv_usec = (long)(now.integer % 1000000LL);
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
49 tp->tv_sec = (long)(now.integer / 1000000LL);
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
50
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
51 /* FIXME CVI redefines the epoch as seconds since 1900-01-01 ! */
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
52 tp->tv_sec += 2208988800;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
53
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
54 return 0;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
55 }
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
56
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
57
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
58 static struct tm * copy_tm_result(struct tm *dest, struct tm const *src)
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
59 {
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
60 if (! src)
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
61 return NULL;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
62 *dest = *src;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
63 return dest;
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
64 }
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
65
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
66
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
67 struct tm * gmtime_r(time_t const *t, struct tm *tp)
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
68 {
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
69 return copy_tm_result(tp, gmtime(t));
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
70 }
be814b934eca Implement gettimeofday()
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 16
diff changeset
71