diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/util/time.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/util/time.c')
-rw-r--r-- | src/util/time.c | 413 |
1 files changed, 207 insertions, 206 deletions
diff --git a/src/util/time.c b/src/util/time.c index 85a781aff..3df7b469e 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file util/time.c | 22 | * @file util/time.c |
@@ -37,7 +37,7 @@ | |||
37 | #endif | 37 | #endif |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-time", __VA_ARGS__) | 40 | #define LOG(kind, ...) GNUNET_log_from(kind, "util-time", __VA_ARGS__) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Variable used to simulate clock skew. Used for testing, never in production. | 43 | * Variable used to simulate clock skew. Used for testing, never in production. |
@@ -50,7 +50,7 @@ static long long timestamp_offset; | |||
50 | * @param offset the offset to skew the locale time by | 50 | * @param offset the offset to skew the locale time by |
51 | */ | 51 | */ |
52 | void | 52 | void |
53 | GNUNET_TIME_set_offset (long long offset) | 53 | GNUNET_TIME_set_offset(long long offset) |
54 | { | 54 | { |
55 | timestamp_offset = offset; | 55 | timestamp_offset = offset; |
56 | } | 56 | } |
@@ -62,7 +62,7 @@ GNUNET_TIME_set_offset (long long offset) | |||
62 | * @return the offset we currently skew the locale time by | 62 | * @return the offset we currently skew the locale time by |
63 | */ | 63 | */ |
64 | long long | 64 | long long |
65 | GNUNET_TIME_get_offset () | 65 | GNUNET_TIME_get_offset() |
66 | { | 66 | { |
67 | return timestamp_offset; | 67 | return timestamp_offset; |
68 | } | 68 | } |
@@ -77,7 +77,7 @@ GNUNET_TIME_get_offset () | |||
77 | * it was just now rounded | 77 | * it was just now rounded |
78 | */ | 78 | */ |
79 | int | 79 | int |
80 | GNUNET_TIME_round_abs (struct GNUNET_TIME_Absolute *at) | 80 | GNUNET_TIME_round_abs(struct GNUNET_TIME_Absolute *at) |
81 | { | 81 | { |
82 | if (at->abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 82 | if (at->abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
83 | return GNUNET_OK; | 83 | return GNUNET_OK; |
@@ -97,7 +97,7 @@ GNUNET_TIME_round_abs (struct GNUNET_TIME_Absolute *at) | |||
97 | * it was just now rounded | 97 | * it was just now rounded |
98 | */ | 98 | */ |
99 | int | 99 | int |
100 | GNUNET_TIME_round_rel (struct GNUNET_TIME_Relative *rt) | 100 | GNUNET_TIME_round_rel(struct GNUNET_TIME_Relative *rt) |
101 | { | 101 | { |
102 | if (rt->rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | 102 | if (rt->rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) |
103 | return GNUNET_OK; | 103 | return GNUNET_OK; |
@@ -115,14 +115,14 @@ GNUNET_TIME_round_rel (struct GNUNET_TIME_Relative *rt) | |||
115 | * @return the current time | 115 | * @return the current time |
116 | */ | 116 | */ |
117 | struct GNUNET_TIME_Absolute | 117 | struct GNUNET_TIME_Absolute |
118 | GNUNET_TIME_absolute_get () | 118 | GNUNET_TIME_absolute_get() |
119 | { | 119 | { |
120 | struct GNUNET_TIME_Absolute ret; | 120 | struct GNUNET_TIME_Absolute ret; |
121 | struct timeval tv; | 121 | struct timeval tv; |
122 | 122 | ||
123 | gettimeofday (&tv, NULL); | 123 | gettimeofday(&tv, NULL); |
124 | ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL) + | 124 | ret.abs_value_us = (uint64_t)(((uint64_t)tv.tv_sec * 1000LL * 1000LL) + |
125 | ((uint64_t) tv.tv_usec)) + | 125 | ((uint64_t)tv.tv_usec)) + |
126 | timestamp_offset; | 126 | timestamp_offset; |
127 | return ret; | 127 | return ret; |
128 | } | 128 | } |
@@ -132,7 +132,7 @@ GNUNET_TIME_absolute_get () | |||
132 | * Return relative time of 0ms. | 132 | * Return relative time of 0ms. |
133 | */ | 133 | */ |
134 | struct GNUNET_TIME_Relative | 134 | struct GNUNET_TIME_Relative |
135 | GNUNET_TIME_relative_get_zero_ () | 135 | GNUNET_TIME_relative_get_zero_() |
136 | { | 136 | { |
137 | static struct GNUNET_TIME_Relative zero; | 137 | static struct GNUNET_TIME_Relative zero; |
138 | 138 | ||
@@ -144,7 +144,7 @@ GNUNET_TIME_relative_get_zero_ () | |||
144 | * Return absolute time of 0ms. | 144 | * Return absolute time of 0ms. |
145 | */ | 145 | */ |
146 | struct GNUNET_TIME_Absolute | 146 | struct GNUNET_TIME_Absolute |
147 | GNUNET_TIME_absolute_get_zero_ () | 147 | GNUNET_TIME_absolute_get_zero_() |
148 | { | 148 | { |
149 | static struct GNUNET_TIME_Absolute zero; | 149 | static struct GNUNET_TIME_Absolute zero; |
150 | 150 | ||
@@ -156,9 +156,9 @@ GNUNET_TIME_absolute_get_zero_ () | |||
156 | * Return relative time of 1us. | 156 | * Return relative time of 1us. |
157 | */ | 157 | */ |
158 | struct GNUNET_TIME_Relative | 158 | struct GNUNET_TIME_Relative |
159 | GNUNET_TIME_relative_get_unit_ () | 159 | GNUNET_TIME_relative_get_unit_() |
160 | { | 160 | { |
161 | static struct GNUNET_TIME_Relative one = {1}; | 161 | static struct GNUNET_TIME_Relative one = { 1 }; |
162 | 162 | ||
163 | return one; | 163 | return one; |
164 | } | 164 | } |
@@ -168,9 +168,9 @@ GNUNET_TIME_relative_get_unit_ () | |||
168 | * Return relative time of 1ms. | 168 | * Return relative time of 1ms. |
169 | */ | 169 | */ |
170 | struct GNUNET_TIME_Relative | 170 | struct GNUNET_TIME_Relative |
171 | GNUNET_TIME_relative_get_millisecond_ () | 171 | GNUNET_TIME_relative_get_millisecond_() |
172 | { | 172 | { |
173 | static struct GNUNET_TIME_Relative one = {1000}; | 173 | static struct GNUNET_TIME_Relative one = { 1000 }; |
174 | 174 | ||
175 | return one; | 175 | return one; |
176 | } | 176 | } |
@@ -180,9 +180,9 @@ GNUNET_TIME_relative_get_millisecond_ () | |||
180 | * Return relative time of 1s. | 180 | * Return relative time of 1s. |
181 | */ | 181 | */ |
182 | struct GNUNET_TIME_Relative | 182 | struct GNUNET_TIME_Relative |
183 | GNUNET_TIME_relative_get_second_ () | 183 | GNUNET_TIME_relative_get_second_() |
184 | { | 184 | { |
185 | static struct GNUNET_TIME_Relative one = {1000 * 1000LL}; | 185 | static struct GNUNET_TIME_Relative one = { 1000 * 1000LL }; |
186 | 186 | ||
187 | return one; | 187 | return one; |
188 | } | 188 | } |
@@ -192,9 +192,9 @@ GNUNET_TIME_relative_get_second_ () | |||
192 | * Return relative time of 1 minute. | 192 | * Return relative time of 1 minute. |
193 | */ | 193 | */ |
194 | struct GNUNET_TIME_Relative | 194 | struct GNUNET_TIME_Relative |
195 | GNUNET_TIME_relative_get_minute_ () | 195 | GNUNET_TIME_relative_get_minute_() |
196 | { | 196 | { |
197 | static struct GNUNET_TIME_Relative one = {60 * 1000 * 1000LL}; | 197 | static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL }; |
198 | 198 | ||
199 | return one; | 199 | return one; |
200 | } | 200 | } |
@@ -204,9 +204,9 @@ GNUNET_TIME_relative_get_minute_ () | |||
204 | * Return relative time of 1 hour. | 204 | * Return relative time of 1 hour. |
205 | */ | 205 | */ |
206 | struct GNUNET_TIME_Relative | 206 | struct GNUNET_TIME_Relative |
207 | GNUNET_TIME_relative_get_hour_ () | 207 | GNUNET_TIME_relative_get_hour_() |
208 | { | 208 | { |
209 | static struct GNUNET_TIME_Relative one = {60 * 60 * 1000 * 1000LL}; | 209 | static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL }; |
210 | 210 | ||
211 | return one; | 211 | return one; |
212 | } | 212 | } |
@@ -216,9 +216,9 @@ GNUNET_TIME_relative_get_hour_ () | |||
216 | * Return "forever". | 216 | * Return "forever". |
217 | */ | 217 | */ |
218 | struct GNUNET_TIME_Relative | 218 | struct GNUNET_TIME_Relative |
219 | GNUNET_TIME_relative_get_forever_ () | 219 | GNUNET_TIME_relative_get_forever_() |
220 | { | 220 | { |
221 | static struct GNUNET_TIME_Relative forever = {UINT64_MAX}; | 221 | static struct GNUNET_TIME_Relative forever = { UINT64_MAX }; |
222 | 222 | ||
223 | return forever; | 223 | return forever; |
224 | } | 224 | } |
@@ -228,9 +228,10 @@ GNUNET_TIME_relative_get_forever_ () | |||
228 | * Return "forever". | 228 | * Return "forever". |
229 | */ | 229 | */ |
230 | struct GNUNET_TIME_Absolute | 230 | struct GNUNET_TIME_Absolute |
231 | GNUNET_TIME_absolute_get_forever_ () | 231 | GNUNET_TIME_absolute_get_forever_() |
232 | { | 232 | { |
233 | static struct GNUNET_TIME_Absolute forever = {UINT64_MAX}; | 233 | static struct GNUNET_TIME_Absolute forever = { UINT64_MAX }; |
234 | |||
234 | return forever; | 235 | return forever; |
235 | } | 236 | } |
236 | 237 | ||
@@ -242,19 +243,19 @@ GNUNET_TIME_absolute_get_forever_ () | |||
242 | * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow) | 243 | * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow) |
243 | */ | 244 | */ |
244 | struct GNUNET_TIME_Absolute | 245 | struct GNUNET_TIME_Absolute |
245 | GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) | 246 | GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel) |
246 | { | 247 | { |
247 | struct GNUNET_TIME_Absolute ret; | 248 | struct GNUNET_TIME_Absolute ret; |
248 | 249 | ||
249 | if (rel.rel_value_us == UINT64_MAX) | 250 | if (rel.rel_value_us == UINT64_MAX) |
250 | return GNUNET_TIME_UNIT_FOREVER_ABS; | 251 | return GNUNET_TIME_UNIT_FOREVER_ABS; |
251 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 252 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); |
252 | 253 | ||
253 | if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us) | 254 | if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us) |
254 | { | 255 | { |
255 | GNUNET_break (0); /* overflow... */ | 256 | GNUNET_break(0); /* overflow... */ |
256 | return GNUNET_TIME_UNIT_FOREVER_ABS; | 257 | return GNUNET_TIME_UNIT_FOREVER_ABS; |
257 | } | 258 | } |
258 | ret.abs_value_us = rel.rel_value_us + now.abs_value_us; | 259 | ret.abs_value_us = rel.rel_value_us + now.abs_value_us; |
259 | return ret; | 260 | return ret; |
260 | } | 261 | } |
@@ -268,8 +269,8 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) | |||
268 | * @return timestamp that is smaller | 269 | * @return timestamp that is smaller |
269 | */ | 270 | */ |
270 | struct GNUNET_TIME_Relative | 271 | struct GNUNET_TIME_Relative |
271 | GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, | 272 | GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, |
272 | struct GNUNET_TIME_Relative t2) | 273 | struct GNUNET_TIME_Relative t2) |
273 | { | 274 | { |
274 | return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2; | 275 | return (t1.rel_value_us < t2.rel_value_us) ? t1 : t2; |
275 | } | 276 | } |
@@ -283,8 +284,8 @@ GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, | |||
283 | * @return timestamp that is larger | 284 | * @return timestamp that is larger |
284 | */ | 285 | */ |
285 | struct GNUNET_TIME_Relative | 286 | struct GNUNET_TIME_Relative |
286 | GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, | 287 | GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, |
287 | struct GNUNET_TIME_Relative t2) | 288 | struct GNUNET_TIME_Relative t2) |
288 | { | 289 | { |
289 | return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2; | 290 | return (t1.rel_value_us > t2.rel_value_us) ? t1 : t2; |
290 | } | 291 | } |
@@ -298,8 +299,8 @@ GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, | |||
298 | * @return timestamp that is smaller | 299 | * @return timestamp that is smaller |
299 | */ | 300 | */ |
300 | struct GNUNET_TIME_Absolute | 301 | struct GNUNET_TIME_Absolute |
301 | GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, | 302 | GNUNET_TIME_absolute_min(struct GNUNET_TIME_Absolute t1, |
302 | struct GNUNET_TIME_Absolute t2) | 303 | struct GNUNET_TIME_Absolute t2) |
303 | { | 304 | { |
304 | return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2; | 305 | return (t1.abs_value_us < t2.abs_value_us) ? t1 : t2; |
305 | } | 306 | } |
@@ -313,8 +314,8 @@ GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, | |||
313 | * @return timestamp that is bigger | 314 | * @return timestamp that is bigger |
314 | */ | 315 | */ |
315 | struct GNUNET_TIME_Absolute | 316 | struct GNUNET_TIME_Absolute |
316 | GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, | 317 | GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, |
317 | struct GNUNET_TIME_Absolute t2) | 318 | struct GNUNET_TIME_Absolute t2) |
318 | { | 319 | { |
319 | return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2; | 320 | return (t1.abs_value_us > t2.abs_value_us) ? t1 : t2; |
320 | } | 321 | } |
@@ -327,13 +328,13 @@ GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, | |||
327 | * @return future - now, or 0 if now >= future, or FOREVER if future==FOREVER. | 328 | * @return future - now, or 0 if now >= future, or FOREVER if future==FOREVER. |
328 | */ | 329 | */ |
329 | struct GNUNET_TIME_Relative | 330 | struct GNUNET_TIME_Relative |
330 | GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) | 331 | GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future) |
331 | { | 332 | { |
332 | struct GNUNET_TIME_Relative ret; | 333 | struct GNUNET_TIME_Relative ret; |
333 | 334 | ||
334 | if (future.abs_value_us == UINT64_MAX) | 335 | if (future.abs_value_us == UINT64_MAX) |
335 | return GNUNET_TIME_UNIT_FOREVER_REL; | 336 | return GNUNET_TIME_UNIT_FOREVER_REL; |
336 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 337 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); |
337 | 338 | ||
338 | if (now.abs_value_us > future.abs_value_us) | 339 | if (now.abs_value_us > future.abs_value_us) |
339 | return GNUNET_TIME_UNIT_ZERO; | 340 | return GNUNET_TIME_UNIT_ZERO; |
@@ -349,8 +350,8 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) | |||
349 | * @return 0 if start >= end; FOREVER if end==FOREVER; otherwise end - start | 350 | * @return 0 if start >= end; FOREVER if end==FOREVER; otherwise end - start |
350 | */ | 351 | */ |
351 | struct GNUNET_TIME_Relative | 352 | struct GNUNET_TIME_Relative |
352 | GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, | 353 | GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, |
353 | struct GNUNET_TIME_Absolute end) | 354 | struct GNUNET_TIME_Absolute end) |
354 | { | 355 | { |
355 | struct GNUNET_TIME_Relative ret; | 356 | struct GNUNET_TIME_Relative ret; |
356 | 357 | ||
@@ -369,12 +370,12 @@ GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, | |||
369 | * @return 0 if whence > now, otherwise now-whence. | 370 | * @return 0 if whence > now, otherwise now-whence. |
370 | */ | 371 | */ |
371 | struct GNUNET_TIME_Relative | 372 | struct GNUNET_TIME_Relative |
372 | GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence) | 373 | GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence) |
373 | { | 374 | { |
374 | struct GNUNET_TIME_Absolute now; | 375 | struct GNUNET_TIME_Absolute now; |
375 | struct GNUNET_TIME_Relative ret; | 376 | struct GNUNET_TIME_Relative ret; |
376 | 377 | ||
377 | now = GNUNET_TIME_absolute_get (); | 378 | now = GNUNET_TIME_absolute_get(); |
378 | if (whence.abs_value_us > now.abs_value_us) | 379 | if (whence.abs_value_us > now.abs_value_us) |
379 | return GNUNET_TIME_UNIT_ZERO; | 380 | return GNUNET_TIME_UNIT_ZERO; |
380 | ret.rel_value_us = now.abs_value_us - whence.abs_value_us; | 381 | ret.rel_value_us = now.abs_value_us - whence.abs_value_us; |
@@ -389,8 +390,8 @@ GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence) | |||
389 | * @return FOREVER if either argument is FOREVER or on overflow; start+duration otherwise | 390 | * @return FOREVER if either argument is FOREVER or on overflow; start+duration otherwise |
390 | */ | 391 | */ |
391 | struct GNUNET_TIME_Absolute | 392 | struct GNUNET_TIME_Absolute |
392 | GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, | 393 | GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, |
393 | struct GNUNET_TIME_Relative duration) | 394 | struct GNUNET_TIME_Relative duration) |
394 | { | 395 | { |
395 | struct GNUNET_TIME_Absolute ret; | 396 | struct GNUNET_TIME_Absolute ret; |
396 | 397 | ||
@@ -398,10 +399,10 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, | |||
398 | (duration.rel_value_us == UINT64_MAX)) | 399 | (duration.rel_value_us == UINT64_MAX)) |
399 | return GNUNET_TIME_UNIT_FOREVER_ABS; | 400 | return GNUNET_TIME_UNIT_FOREVER_ABS; |
400 | if (start.abs_value_us + duration.rel_value_us < start.abs_value_us) | 401 | if (start.abs_value_us + duration.rel_value_us < start.abs_value_us) |
401 | { | 402 | { |
402 | GNUNET_break (0); | 403 | GNUNET_break(0); |
403 | return GNUNET_TIME_UNIT_FOREVER_ABS; | 404 | return GNUNET_TIME_UNIT_FOREVER_ABS; |
404 | } | 405 | } |
405 | ret.abs_value_us = start.abs_value_us + duration.rel_value_us; | 406 | ret.abs_value_us = start.abs_value_us + duration.rel_value_us; |
406 | return ret; | 407 | return ret; |
407 | } | 408 | } |
@@ -416,8 +417,8 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, | |||
416 | * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise | 417 | * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise |
417 | */ | 418 | */ |
418 | struct GNUNET_TIME_Absolute | 419 | struct GNUNET_TIME_Absolute |
419 | GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, | 420 | GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, |
420 | struct GNUNET_TIME_Relative duration) | 421 | struct GNUNET_TIME_Relative duration) |
421 | { | 422 | { |
422 | struct GNUNET_TIME_Absolute ret; | 423 | struct GNUNET_TIME_Absolute ret; |
423 | 424 | ||
@@ -436,8 +437,8 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, | |||
436 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor | 437 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor |
437 | */ | 438 | */ |
438 | struct GNUNET_TIME_Relative | 439 | struct GNUNET_TIME_Relative |
439 | GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, | 440 | GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, |
440 | unsigned long long factor) | 441 | unsigned long long factor) |
441 | { | 442 | { |
442 | struct GNUNET_TIME_Relative ret; | 443 | struct GNUNET_TIME_Relative ret; |
443 | 444 | ||
@@ -447,10 +448,10 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, | |||
447 | return GNUNET_TIME_UNIT_FOREVER_REL; | 448 | return GNUNET_TIME_UNIT_FOREVER_REL; |
448 | ret.rel_value_us = rel.rel_value_us * factor; | 449 | ret.rel_value_us = rel.rel_value_us * factor; |
449 | if (ret.rel_value_us / factor != rel.rel_value_us) | 450 | if (ret.rel_value_us / factor != rel.rel_value_us) |
450 | { | 451 | { |
451 | GNUNET_break (0); | 452 | GNUNET_break(0); |
452 | return GNUNET_TIME_UNIT_FOREVER_REL; | 453 | return GNUNET_TIME_UNIT_FOREVER_REL; |
453 | } | 454 | } |
454 | return ret; | 455 | return ret; |
455 | } | 456 | } |
456 | 457 | ||
@@ -462,27 +463,27 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, | |||
462 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor | 463 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor |
463 | */ | 464 | */ |
464 | struct GNUNET_TIME_Relative | 465 | struct GNUNET_TIME_Relative |
465 | relative_multiply_double (struct GNUNET_TIME_Relative rel, double factor) | 466 | relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor) |
466 | { | 467 | { |
467 | struct GNUNET_TIME_Relative out; | 468 | struct GNUNET_TIME_Relative out; |
468 | double m; | 469 | double m; |
469 | 470 | ||
470 | GNUNET_assert (0 <= factor); | 471 | GNUNET_assert(0 <= factor); |
471 | 472 | ||
472 | if (0 == factor) | 473 | if (0 == factor) |
473 | return GNUNET_TIME_UNIT_ZERO; | 474 | return GNUNET_TIME_UNIT_ZERO; |
474 | if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | 475 | if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) |
475 | return GNUNET_TIME_UNIT_FOREVER_REL; | 476 | return GNUNET_TIME_UNIT_FOREVER_REL; |
476 | 477 | ||
477 | m = ((double) rel.rel_value_us) * factor; | 478 | m = ((double)rel.rel_value_us) * factor; |
478 | 479 | ||
479 | if (m >= (double) (GNUNET_TIME_UNIT_FOREVER_REL).rel_value_us) | 480 | if (m >= (double)(GNUNET_TIME_UNIT_FOREVER_REL).rel_value_us) |
480 | { | 481 | { |
481 | GNUNET_break (0); | 482 | GNUNET_break(0); |
482 | return GNUNET_TIME_UNIT_FOREVER_REL; | 483 | return GNUNET_TIME_UNIT_FOREVER_REL; |
483 | } | 484 | } |
484 | 485 | ||
485 | out.rel_value_us = (uint64_t) m; | 486 | out.rel_value_us = (uint64_t)m; |
486 | return out; | 487 | return out; |
487 | } | 488 | } |
488 | 489 | ||
@@ -495,8 +496,8 @@ relative_multiply_double (struct GNUNET_TIME_Relative rel, double factor) | |||
495 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor | 496 | * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor |
496 | */ | 497 | */ |
497 | struct GNUNET_TIME_Relative | 498 | struct GNUNET_TIME_Relative |
498 | GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel, | 499 | GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, |
499 | unsigned long long factor) | 500 | unsigned long long factor) |
500 | { | 501 | { |
501 | struct GNUNET_TIME_Relative ret; | 502 | struct GNUNET_TIME_Relative ret; |
502 | 503 | ||
@@ -506,9 +507,9 @@ GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel, | |||
506 | return GNUNET_TIME_UNIT_FOREVER_REL; | 507 | return GNUNET_TIME_UNIT_FOREVER_REL; |
507 | ret.rel_value_us = rel.rel_value_us * factor; | 508 | ret.rel_value_us = rel.rel_value_us * factor; |
508 | if (ret.rel_value_us / factor != rel.rel_value_us) | 509 | if (ret.rel_value_us / factor != rel.rel_value_us) |
509 | { | 510 | { |
510 | return GNUNET_TIME_UNIT_FOREVER_REL; | 511 | return GNUNET_TIME_UNIT_FOREVER_REL; |
511 | } | 512 | } |
512 | return ret; | 513 | return ret; |
513 | } | 514 | } |
514 | 515 | ||
@@ -521,8 +522,8 @@ GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel, | |||
521 | * @return FOREVER if rel=FOREVER or factor==0; otherwise rel/factor | 522 | * @return FOREVER if rel=FOREVER or factor==0; otherwise rel/factor |
522 | */ | 523 | */ |
523 | struct GNUNET_TIME_Relative | 524 | struct GNUNET_TIME_Relative |
524 | GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, | 525 | GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, |
525 | unsigned long long factor) | 526 | unsigned long long factor) |
526 | { | 527 | { |
527 | struct GNUNET_TIME_Relative ret; | 528 | struct GNUNET_TIME_Relative ret; |
528 | 529 | ||
@@ -545,22 +546,22 @@ GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, | |||
545 | * assuming it continues at the same speed | 546 | * assuming it continues at the same speed |
546 | */ | 547 | */ |
547 | struct GNUNET_TIME_Relative | 548 | struct GNUNET_TIME_Relative |
548 | GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, | 549 | GNUNET_TIME_calculate_eta(struct GNUNET_TIME_Absolute start, |
549 | uint64_t finished, | 550 | uint64_t finished, |
550 | uint64_t total) | 551 | uint64_t total) |
551 | { | 552 | { |
552 | struct GNUNET_TIME_Relative dur; | 553 | struct GNUNET_TIME_Relative dur; |
553 | double exp; | 554 | double exp; |
554 | struct GNUNET_TIME_Relative ret; | 555 | struct GNUNET_TIME_Relative ret; |
555 | 556 | ||
556 | GNUNET_break (finished <= total); | 557 | GNUNET_break(finished <= total); |
557 | if (finished >= total) | 558 | if (finished >= total) |
558 | return GNUNET_TIME_UNIT_ZERO; | 559 | return GNUNET_TIME_UNIT_ZERO; |
559 | if (0 == finished) | 560 | if (0 == finished) |
560 | return GNUNET_TIME_UNIT_FOREVER_REL; | 561 | return GNUNET_TIME_UNIT_FOREVER_REL; |
561 | dur = GNUNET_TIME_absolute_get_duration (start); | 562 | dur = GNUNET_TIME_absolute_get_duration(start); |
562 | exp = ((double) dur.rel_value_us) * ((double) total) / ((double) finished); | 563 | exp = ((double)dur.rel_value_us) * ((double)total) / ((double)finished); |
563 | ret.rel_value_us = ((uint64_t) exp) - dur.rel_value_us; | 564 | ret.rel_value_us = ((uint64_t)exp) - dur.rel_value_us; |
564 | return ret; | 565 | return ret; |
565 | } | 566 | } |
566 | 567 | ||
@@ -573,18 +574,18 @@ GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, | |||
573 | * @return FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise | 574 | * @return FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise |
574 | */ | 575 | */ |
575 | struct GNUNET_TIME_Relative | 576 | struct GNUNET_TIME_Relative |
576 | GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, | 577 | GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, |
577 | struct GNUNET_TIME_Relative a2) | 578 | struct GNUNET_TIME_Relative a2) |
578 | { | 579 | { |
579 | struct GNUNET_TIME_Relative ret; | 580 | struct GNUNET_TIME_Relative ret; |
580 | 581 | ||
581 | if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX)) | 582 | if ((a1.rel_value_us == UINT64_MAX) || (a2.rel_value_us == UINT64_MAX)) |
582 | return GNUNET_TIME_UNIT_FOREVER_REL; | 583 | return GNUNET_TIME_UNIT_FOREVER_REL; |
583 | if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us) | 584 | if (a1.rel_value_us + a2.rel_value_us < a1.rel_value_us) |
584 | { | 585 | { |
585 | GNUNET_break (0); | 586 | GNUNET_break(0); |
586 | return GNUNET_TIME_UNIT_FOREVER_REL; | 587 | return GNUNET_TIME_UNIT_FOREVER_REL; |
587 | } | 588 | } |
588 | ret.rel_value_us = a1.rel_value_us + a2.rel_value_us; | 589 | ret.rel_value_us = a1.rel_value_us + a2.rel_value_us; |
589 | return ret; | 590 | return ret; |
590 | } | 591 | } |
@@ -598,8 +599,8 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, | |||
598 | * @return ZERO if a2>=a1 (including both FOREVER), FOREVER if a1 is FOREVER, a1-a2 otherwise | 599 | * @return ZERO if a2>=a1 (including both FOREVER), FOREVER if a1 is FOREVER, a1-a2 otherwise |
599 | */ | 600 | */ |
600 | struct GNUNET_TIME_Relative | 601 | struct GNUNET_TIME_Relative |
601 | GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, | 602 | GNUNET_TIME_relative_subtract(struct GNUNET_TIME_Relative a1, |
602 | struct GNUNET_TIME_Relative a2) | 603 | struct GNUNET_TIME_Relative a2) |
603 | { | 604 | { |
604 | struct GNUNET_TIME_Relative ret; | 605 | struct GNUNET_TIME_Relative ret; |
605 | 606 | ||
@@ -619,11 +620,11 @@ GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, | |||
619 | * @return time in network byte order | 620 | * @return time in network byte order |
620 | */ | 621 | */ |
621 | struct GNUNET_TIME_RelativeNBO | 622 | struct GNUNET_TIME_RelativeNBO |
622 | GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a) | 623 | GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a) |
623 | { | 624 | { |
624 | struct GNUNET_TIME_RelativeNBO ret; | 625 | struct GNUNET_TIME_RelativeNBO ret; |
625 | 626 | ||
626 | ret.rel_value_us__ = GNUNET_htonll (a.rel_value_us); | 627 | ret.rel_value_us__ = GNUNET_htonll(a.rel_value_us); |
627 | return ret; | 628 | return ret; |
628 | } | 629 | } |
629 | 630 | ||
@@ -635,11 +636,11 @@ GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a) | |||
635 | * @return time in host byte order | 636 | * @return time in host byte order |
636 | */ | 637 | */ |
637 | struct GNUNET_TIME_Relative | 638 | struct GNUNET_TIME_Relative |
638 | GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a) | 639 | GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a) |
639 | { | 640 | { |
640 | struct GNUNET_TIME_Relative ret; | 641 | struct GNUNET_TIME_Relative ret; |
641 | 642 | ||
642 | ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__); | 643 | ret.rel_value_us = GNUNET_ntohll(a.rel_value_us__); |
643 | return ret; | 644 | return ret; |
644 | } | 645 | } |
645 | 646 | ||
@@ -651,11 +652,11 @@ GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a) | |||
651 | * @return time in network byte order | 652 | * @return time in network byte order |
652 | */ | 653 | */ |
653 | struct GNUNET_TIME_AbsoluteNBO | 654 | struct GNUNET_TIME_AbsoluteNBO |
654 | GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a) | 655 | GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a) |
655 | { | 656 | { |
656 | struct GNUNET_TIME_AbsoluteNBO ret; | 657 | struct GNUNET_TIME_AbsoluteNBO ret; |
657 | 658 | ||
658 | ret.abs_value_us__ = GNUNET_htonll (a.abs_value_us); | 659 | ret.abs_value_us__ = GNUNET_htonll(a.abs_value_us); |
659 | return ret; | 660 | return ret; |
660 | } | 661 | } |
661 | 662 | ||
@@ -667,11 +668,11 @@ GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a) | |||
667 | * @return time in host byte order | 668 | * @return time in host byte order |
668 | */ | 669 | */ |
669 | struct GNUNET_TIME_Absolute | 670 | struct GNUNET_TIME_Absolute |
670 | GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a) | 671 | GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a) |
671 | { | 672 | { |
672 | struct GNUNET_TIME_Absolute ret; | 673 | struct GNUNET_TIME_Absolute ret; |
673 | 674 | ||
674 | ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__); | 675 | ret.abs_value_us = GNUNET_ntohll(a.abs_value_us__); |
675 | return ret; | 676 | return ret; |
676 | } | 677 | } |
677 | 678 | ||
@@ -680,13 +681,13 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a) | |||
680 | * Return the current year (i.e. '2011'). | 681 | * Return the current year (i.e. '2011'). |
681 | */ | 682 | */ |
682 | unsigned int | 683 | unsigned int |
683 | GNUNET_TIME_get_current_year () | 684 | GNUNET_TIME_get_current_year() |
684 | { | 685 | { |
685 | time_t tp; | 686 | time_t tp; |
686 | struct tm *t; | 687 | struct tm *t; |
687 | 688 | ||
688 | tp = time (NULL); | 689 | tp = time(NULL); |
689 | t = gmtime (&tp); | 690 | t = gmtime(&tp); |
690 | if (t == NULL) | 691 | if (t == NULL) |
691 | return 0; | 692 | return 0; |
692 | return t->tm_year + 1900; | 693 | return t->tm_year + 1900; |
@@ -700,13 +701,13 @@ GNUNET_TIME_get_current_year () | |||
700 | * @return year a year (after 1970), 0 on error | 701 | * @return year a year (after 1970), 0 on error |
701 | */ | 702 | */ |
702 | unsigned int | 703 | unsigned int |
703 | GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at) | 704 | GNUNET_TIME_time_to_year(struct GNUNET_TIME_Absolute at) |
704 | { | 705 | { |
705 | struct tm *t; | 706 | struct tm *t; |
706 | time_t tp; | 707 | time_t tp; |
707 | 708 | ||
708 | tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */ | 709 | tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */ |
709 | t = gmtime (&tp); | 710 | t = gmtime(&tp); |
710 | if (t == NULL) | 711 | if (t == NULL) |
711 | return 0; | 712 | return 0; |
712 | return t->tm_year + 1900; | 713 | return t->tm_year + 1900; |
@@ -720,25 +721,25 @@ GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at) | |||
720 | * @return absolute time for January 1st of that year. | 721 | * @return absolute time for January 1st of that year. |
721 | */ | 722 | */ |
722 | struct GNUNET_TIME_Absolute | 723 | struct GNUNET_TIME_Absolute |
723 | GNUNET_TIME_year_to_time (unsigned int year) | 724 | GNUNET_TIME_year_to_time(unsigned int year) |
724 | { | 725 | { |
725 | struct GNUNET_TIME_Absolute ret; | 726 | struct GNUNET_TIME_Absolute ret; |
726 | time_t tp; | 727 | time_t tp; |
727 | struct tm t; | 728 | struct tm t; |
728 | 729 | ||
729 | memset (&t, 0, sizeof (t)); | 730 | memset(&t, 0, sizeof(t)); |
730 | if (year < 1900) | 731 | if (year < 1900) |
731 | { | 732 | { |
732 | GNUNET_break (0); | 733 | GNUNET_break(0); |
733 | return GNUNET_TIME_absolute_get (); /* now */ | 734 | return GNUNET_TIME_absolute_get(); /* now */ |
734 | } | 735 | } |
735 | t.tm_year = year - 1900; | 736 | t.tm_year = year - 1900; |
736 | t.tm_mday = 1; | 737 | t.tm_mday = 1; |
737 | t.tm_mon = 0; | 738 | t.tm_mon = 0; |
738 | t.tm_wday = 1; | 739 | t.tm_wday = 1; |
739 | t.tm_yday = 1; | 740 | t.tm_yday = 1; |
740 | tp = mktime (&t); | 741 | tp = mktime(&t); |
741 | GNUNET_break (tp != (time_t) -1); | 742 | GNUNET_break(tp != (time_t)-1); |
742 | ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */ | 743 | ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */ |
743 | return ret; | 744 | return ret; |
744 | } | 745 | } |
@@ -754,16 +755,16 @@ GNUNET_TIME_year_to_time (unsigned int year) | |||
754 | * @return the next backoff time | 755 | * @return the next backoff time |
755 | */ | 756 | */ |
756 | struct GNUNET_TIME_Relative | 757 | struct GNUNET_TIME_Relative |
757 | GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt, | 758 | GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, |
758 | struct GNUNET_TIME_Relative threshold) | 759 | struct GNUNET_TIME_Relative threshold) |
759 | { | 760 | { |
760 | double r = (rand () % 500) / 1000.0; | 761 | double r = (rand() % 500) / 1000.0; |
761 | struct GNUNET_TIME_Relative t; | 762 | struct GNUNET_TIME_Relative t; |
762 | 763 | ||
763 | t = relative_multiply_double ( | 764 | t = relative_multiply_double( |
764 | GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, rt), | 765 | GNUNET_TIME_relative_max(GNUNET_TIME_UNIT_MILLISECONDS, rt), |
765 | 2 + r); | 766 | 2 + r); |
766 | return GNUNET_TIME_relative_min (threshold, t); | 767 | return GNUNET_TIME_relative_min(threshold, t); |
767 | } | 768 | } |
768 | 769 | ||
769 | 770 | ||
@@ -774,11 +775,11 @@ GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt, | |||
774 | * @return randomized time | 775 | * @return randomized time |
775 | */ | 776 | */ |
776 | struct GNUNET_TIME_Relative | 777 | struct GNUNET_TIME_Relative |
777 | GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r) | 778 | GNUNET_TIME_randomize(struct GNUNET_TIME_Relative r) |
778 | { | 779 | { |
779 | double d = ((rand () % 1001) - 500) / 1000.0; | 780 | double d = ((rand() % 1001) - 500) / 1000.0; |
780 | 781 | ||
781 | return relative_multiply_double (r, d); | 782 | return relative_multiply_double(r, d); |
782 | } | 783 | } |
783 | 784 | ||
784 | 785 | ||
@@ -801,7 +802,7 @@ GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r) | |||
801 | * @return monotonically increasing time | 802 | * @return monotonically increasing time |
802 | */ | 803 | */ |
803 | struct GNUNET_TIME_Absolute | 804 | struct GNUNET_TIME_Absolute |
804 | GNUNET_TIME_absolute_get_monotonic ( | 805 | GNUNET_TIME_absolute_get_monotonic( |
805 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 806 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
806 | { | 807 | { |
807 | static const struct GNUNET_CONFIGURATION_Handle *last_cfg; | 808 | static const struct GNUNET_CONFIGURATION_Handle *last_cfg; |
@@ -810,114 +811,114 @@ GNUNET_TIME_absolute_get_monotonic ( | |||
810 | static ATOMIC volatile uint64_t *map; | 811 | static ATOMIC volatile uint64_t *map; |
811 | struct GNUNET_TIME_Absolute now; | 812 | struct GNUNET_TIME_Absolute now; |
812 | 813 | ||
813 | now = GNUNET_TIME_absolute_get (); | 814 | now = GNUNET_TIME_absolute_get(); |
814 | if (last_cfg != cfg) | 815 | if (last_cfg != cfg) |
815 | { | ||
816 | char *filename; | ||
817 | |||
818 | if (NULL != map_handle) | ||
819 | { | 816 | { |
820 | GNUNET_DISK_file_unmap (map_handle); | 817 | char *filename; |
821 | map_handle = NULL; | ||
822 | } | ||
823 | map = NULL; | ||
824 | |||
825 | last_cfg = cfg; | ||
826 | if ((NULL != cfg) && | ||
827 | (GNUNET_OK == | ||
828 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
829 | "util", | ||
830 | "MONOTONIC_TIME_FILENAME", | ||
831 | &filename))) | ||
832 | { | ||
833 | struct GNUNET_DISK_FileHandle *fh; | ||
834 | |||
835 | fh = GNUNET_DISK_file_open (filename, | ||
836 | GNUNET_DISK_OPEN_READWRITE | | ||
837 | GNUNET_DISK_OPEN_CREATE, | ||
838 | GNUNET_DISK_PERM_USER_WRITE | | ||
839 | GNUNET_DISK_PERM_GROUP_WRITE | | ||
840 | GNUNET_DISK_PERM_USER_READ | | ||
841 | GNUNET_DISK_PERM_GROUP_READ); | ||
842 | if (NULL == fh) | ||
843 | { | ||
844 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
845 | _ ("Failed to map `%s', cannot assure monotonic time!\n"), | ||
846 | filename); | ||
847 | } | ||
848 | else | ||
849 | { | ||
850 | off_t size; | ||
851 | |||
852 | size = 0; | ||
853 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &size)); | ||
854 | if (size < (off_t) sizeof (*map)) | ||
855 | { | ||
856 | struct GNUNET_TIME_AbsoluteNBO o; | ||
857 | 818 | ||
858 | o = GNUNET_TIME_absolute_hton (now); | 819 | if (NULL != map_handle) |
859 | if (sizeof (o) != GNUNET_DISK_file_write (fh, &o, sizeof (o))) | ||
860 | size = 0; | ||
861 | else | ||
862 | size = sizeof (o); | ||
863 | } | ||
864 | if (size == sizeof (*map)) | ||
865 | { | 820 | { |
866 | map = GNUNET_DISK_file_map (fh, | 821 | GNUNET_DISK_file_unmap(map_handle); |
867 | &map_handle, | 822 | map_handle = NULL; |
868 | GNUNET_DISK_MAP_TYPE_READWRITE, | ||
869 | sizeof (*map)); | ||
870 | if (NULL == map) | ||
871 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
872 | _ ( | ||
873 | "Failed to map `%s', cannot assure monotonic time!\n"), | ||
874 | filename); | ||
875 | } | 823 | } |
876 | else | 824 | map = NULL; |
825 | |||
826 | last_cfg = cfg; | ||
827 | if ((NULL != cfg) && | ||
828 | (GNUNET_OK == | ||
829 | GNUNET_CONFIGURATION_get_value_filename(cfg, | ||
830 | "util", | ||
831 | "MONOTONIC_TIME_FILENAME", | ||
832 | &filename))) | ||
877 | { | 833 | { |
878 | GNUNET_log ( | 834 | struct GNUNET_DISK_FileHandle *fh; |
879 | GNUNET_ERROR_TYPE_WARNING, | 835 | |
880 | _ ( | 836 | fh = GNUNET_DISK_file_open(filename, |
881 | "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"), | 837 | GNUNET_DISK_OPEN_READWRITE | |
882 | filename); | 838 | GNUNET_DISK_OPEN_CREATE, |
839 | GNUNET_DISK_PERM_USER_WRITE | | ||
840 | GNUNET_DISK_PERM_GROUP_WRITE | | ||
841 | GNUNET_DISK_PERM_USER_READ | | ||
842 | GNUNET_DISK_PERM_GROUP_READ); | ||
843 | if (NULL == fh) | ||
844 | { | ||
845 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
846 | _("Failed to map `%s', cannot assure monotonic time!\n"), | ||
847 | filename); | ||
848 | } | ||
849 | else | ||
850 | { | ||
851 | off_t size; | ||
852 | |||
853 | size = 0; | ||
854 | GNUNET_break(GNUNET_OK == GNUNET_DISK_file_handle_size(fh, &size)); | ||
855 | if (size < (off_t)sizeof(*map)) | ||
856 | { | ||
857 | struct GNUNET_TIME_AbsoluteNBO o; | ||
858 | |||
859 | o = GNUNET_TIME_absolute_hton(now); | ||
860 | if (sizeof(o) != GNUNET_DISK_file_write(fh, &o, sizeof(o))) | ||
861 | size = 0; | ||
862 | else | ||
863 | size = sizeof(o); | ||
864 | } | ||
865 | if (size == sizeof(*map)) | ||
866 | { | ||
867 | map = GNUNET_DISK_file_map(fh, | ||
868 | &map_handle, | ||
869 | GNUNET_DISK_MAP_TYPE_READWRITE, | ||
870 | sizeof(*map)); | ||
871 | if (NULL == map) | ||
872 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
873 | _( | ||
874 | "Failed to map `%s', cannot assure monotonic time!\n"), | ||
875 | filename); | ||
876 | } | ||
877 | else | ||
878 | { | ||
879 | GNUNET_log( | ||
880 | GNUNET_ERROR_TYPE_WARNING, | ||
881 | _( | ||
882 | "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"), | ||
883 | filename); | ||
884 | } | ||
885 | } | ||
886 | GNUNET_DISK_file_close(fh); | ||
887 | GNUNET_free(filename); | ||
883 | } | 888 | } |
884 | } | ||
885 | GNUNET_DISK_file_close (fh); | ||
886 | GNUNET_free (filename); | ||
887 | } | 889 | } |
888 | } | ||
889 | if (NULL != map) | 890 | if (NULL != map) |
890 | { | 891 | { |
891 | struct GNUNET_TIME_AbsoluteNBO mt; | 892 | struct GNUNET_TIME_AbsoluteNBO mt; |
892 | 893 | ||
893 | #if __STDC_NO_ATOMICS__ | 894 | #if __STDC_NO_ATOMICS__ |
894 | #if __GNUC__ | 895 | #if __GNUC__ |
895 | mt.abs_value_us__ = __sync_fetch_and_or (map, 0); | 896 | mt.abs_value_us__ = __sync_fetch_and_or(map, 0); |
896 | #else | 897 | #else |
897 | mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */ | 898 | mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */ |
898 | #endif | 899 | #endif |
899 | #else | 900 | #else |
900 | mt.abs_value_us__ = atomic_load (map); | 901 | mt.abs_value_us__ = atomic_load(map); |
901 | #endif | 902 | #endif |
902 | last_time = | 903 | last_time = |
903 | GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt), last_time); | 904 | GNUNET_TIME_absolute_max(GNUNET_TIME_absolute_ntoh(mt), last_time); |
904 | } | 905 | } |
905 | if (now.abs_value_us <= last_time.abs_value_us) | 906 | if (now.abs_value_us <= last_time.abs_value_us) |
906 | now.abs_value_us = last_time.abs_value_us + 1; | 907 | now.abs_value_us = last_time.abs_value_us + 1; |
907 | last_time = now; | 908 | last_time = now; |
908 | if (NULL != map) | 909 | if (NULL != map) |
909 | { | 910 | { |
910 | uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__; | 911 | uint64_t val = GNUNET_TIME_absolute_hton(now).abs_value_us__; |
911 | #if __STDC_NO_ATOMICS__ | 912 | #if __STDC_NO_ATOMICS__ |
912 | #if __GNUC__ | 913 | #if __GNUC__ |
913 | (void) __sync_lock_test_and_set (map, val); | 914 | (void)__sync_lock_test_and_set(map, val); |
914 | #else | 915 | #else |
915 | *map = val; /* godspeed, pray this is atomic */ | 916 | *map = val; /* godspeed, pray this is atomic */ |
916 | #endif | 917 | #endif |
917 | #else | 918 | #else |
918 | atomic_store (map, val); | 919 | atomic_store(map, val); |
919 | #endif | 920 | #endif |
920 | } | 921 | } |
921 | return now; | 922 | return now; |
922 | } | 923 | } |
923 | 924 | ||
@@ -925,9 +926,9 @@ GNUNET_TIME_absolute_get_monotonic ( | |||
925 | /** | 926 | /** |
926 | * Destructor | 927 | * Destructor |
927 | */ | 928 | */ |
928 | void __attribute__ ((destructor)) GNUNET_util_time_fini () | 929 | void __attribute__ ((destructor)) GNUNET_util_time_fini() |
929 | { | 930 | { |
930 | (void) GNUNET_TIME_absolute_get_monotonic (NULL); | 931 | (void)GNUNET_TIME_absolute_get_monotonic(NULL); |
931 | } | 932 | } |
932 | 933 | ||
933 | /* end of time.c */ | 934 | /* end of time.c */ |