-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdlutil.h
182 lines (137 loc) · 3.48 KB
/
dlutil.h
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
* @file dlutil.h
* @brief Utility functions (moslty timing)
* @author Dominique LaSalle <[email protected]>
* Copyright (c) 2013-2015, Dominique LaSalle
* @version 1
* @date 2013-09-11
*/
#ifndef DL_UTIL_H
#define DL_UTIL_H
#include "domlib.h"
/******************************************************************************
* Enums and Structs ***********************************************************
******************************************************************************/
typedef enum dl_timer_state_t {
DL_TIMER_RUNNING = 1,
DL_TIMER_STOPPED = 2
} dl_timer_state_t;
typedef struct dl_timer_t {
double duration;
double start;
dl_timer_state_t state;
} dl_timer_t;
/******************************************************************************
* Function Prototypes *********************************************************
******************************************************************************/
/**
* @brief Convert a set of elements to network byte order.
*
* @param dst Where to write the bytes.
* @param src The source elements.
* @param width The width of each element (in bytes).
*/
void dl_to_bytes(
void * dst,
void const * src,
size_t width);
/**
* @brief Convert a set of bytes in network byte order to native machine order.
*
* @param dst Where to write the elmenents.
* @param src Where to read the bytes from.
* @param width The width of each elements.
*/
void dl_from_bytes(
void * dst,
void const * src,
size_t width);
/**
* @brief Retrieve the wall clock time from the system as a double (seconds
* from the epoch).
*
* @return The seconds passed since 1/1/1970.
*/
double dl_wctime(void);
/**
* @brief Initialize a wall clock timer structure.
*
* @param timer The timer to initialize.
*/
void dl_init_timer(
dl_timer_t * timer);
/**
* @brief Start/resume a wall clock timer.
*
* @param timer The timer to start/resume.
*
* @return The time on the timer when it starts.
*/
double dl_start_timer(
dl_timer_t * timer);
/**
* @brief Stop a wall clock timer.
*
* @param timer The timer to stop.
*
* @return The time on the timer.
*/
double dl_stop_timer(
dl_timer_t * timer);
/**
* @brief Reset a timer so that the elapsed time is 0.
*
* @param timer The timer to reset.
*
* @return The time on timer before it was cleared.
*/
double dl_reset_timer(
dl_timer_t * timer);
/**
* @brief Retrieve the amount of time on a (stopped) wall clock timer.
*
* @param timer The timer to get the time from.
*
* @return The elapsed time.
*/
double dl_poll_timer(
dl_timer_t const * timer);
/**
* @brief Combine the time of two timers.
*
* @param timer1 The timer to increase the duration of.
* @param timer2 The timer to add to the first timer.
*
*/
void dl_combine_timer(
dl_timer_t * timer1,
dl_timer_t const * timer2);
/**
* @brief Compare the elapsed time in two timers. They should both be stopped.
*
* @param timer1 The first timer.
* @param timer2 The second timer.
*
* @return The difference in elapsed time.
*/
double dl_diff_timer(
dl_timer_t const * timer1,
dl_timer_t const * timer2);
/**
* @brief Initialize the random seed using the system clock.
*/
void dl_init_rand(void);
/**
* @brief Set the random seed to use.
*
* @param seed The random seed.
*/
void dl_set_rand(
unsigned int seed);
/**
* @brief Generate a 32-bit random number.
*
* @return The generated number.
*/
unsigned int * dl_get_rand(void);
#endif