forked from mehmetgok/fifo_test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_test.cpp
More file actions
91 lines (50 loc) · 1.15 KB
/
Copy pathtime_test.cpp
File metadata and controls
91 lines (50 loc) · 1.15 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#include <signal.h> /* Ctrl+C Handling */
#include <unistd.h>
#include <stdint.h> /* EXtra types */
#include "fifo.h"
fifo *time_ticks;
static volatile int keepRunning = 1;
void intrHandler(int dummy) {
keepRunning = 0;
}
uint64_t time_value, file_value;
int main(void) {
struct timeval start, end;
int count = 0;
FILE * pFile;
pFile = fopen ("myfile.txt","w");
signal(SIGINT, intrHandler);
time_ticks = new fifo;
while (1) {
gettimeofday(&start, NULL);
time_value = (start.tv_sec * (uint64_t)1000000) + (start.tv_usec);
if (time_ticks->free()>0)
{
printf("Free:%d\r\n", time_ticks->free() );
time_ticks->put(time_value);
}
else
{
printf("No Room for the value, free: %d\r\n", time_ticks->free() );
break;
}
count++;
if (count > 1000)
break;
// Sleep for 1 ms
usleep(1000);
}
while (time_ticks->available())
{
time_ticks->get(&file_value);
fprintf (pFile, "%ld\r\n", file_value);
}
fclose(pFile);
delete time_ticks;
return 0;
}