aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_time_lib.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-27 21:46:41 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-27 21:46:41 +0000
commit46a63dc665f31fa7d42639ab6adabbdb1af239c8 (patch)
tree6c3e58a7f57d6d3ee44aa6cd2808b5458d75de4b /src/include/gnunet_time_lib.h
parent4848a679018f9e864cd277345191ad8f1000b5ff (diff)
downloadgnunet-46a63dc665f31fa7d42639ab6adabbdb1af239c8.tar.gz
gnunet-46a63dc665f31fa7d42639ab6adabbdb1af239c8.zip
renaming GNUNET_TIME_relative_get_forever and GNUNET_TIME_absolute_get_forever methods, adding underscore, to make it clear that the respective #defines should be used instead; replacing use of direct function calls with respective macros where applicable; adding additional GNUNET_TIME_relative_get_xxx-functions to avoid calls to GNUNET_TIME_relative_multiply, which turn out to have gotten performance-relevant
Diffstat (limited to 'src/include/gnunet_time_lib.h')
-rw-r--r--src/include/gnunet_time_lib.h70
1 files changed, 57 insertions, 13 deletions
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index 7090c33a1..35d180ce2 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -90,32 +90,32 @@ GNUNET_NETWORK_STRUCT_END
90/** 90/**
91 * Relative time zero. 91 * Relative time zero.
92 */ 92 */
93#define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero() 93#define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero_()
94 94
95/** 95/**
96 * Absolute time zero. 96 * Absolute time zero.
97 */ 97 */
98#define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero() 98#define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero_()
99 99
100/** 100/**
101 * One millisecond, our basic time unit. 101 * One millisecond, our basic time unit.
102 */ 102 */
103#define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_unit() 103#define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_unit_()
104 104
105/** 105/**
106 * One second. 106 * One second.
107 */ 107 */
108#define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1000) 108#define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_get_second_()
109 109
110/** 110/**
111 * One minute. 111 * One minute.
112 */ 112 */
113#define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) 113#define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_get_minute_()
114 114
115/** 115/**
116 * One hour. 116 * One hour.
117 */ 117 */
118#define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) 118#define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_get_hour_()
119 119
120/** 120/**
121 * One day. 121 * One day.
@@ -141,43 +141,70 @@ GNUNET_NETWORK_STRUCT_END
141 * Constant used to specify "forever". This constant 141 * Constant used to specify "forever". This constant
142 * will be treated specially in all time operations. 142 * will be treated specially in all time operations.
143 */ 143 */
144#define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever () 144#define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever_ ()
145 145
146/** 146/**
147 * Constant used to specify "forever". This constant 147 * Constant used to specify "forever". This constant
148 * will be treated specially in all time operations. 148 * will be treated specially in all time operations.
149 */ 149 */
150#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever () 150#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ ()
151
151 152
152/** 153/**
153 * Return relative time of 0ms. 154 * Return relative time of 0ms.
154 */ 155 */
155struct GNUNET_TIME_Relative 156struct GNUNET_TIME_Relative
156GNUNET_TIME_relative_get_zero (void); 157GNUNET_TIME_relative_get_zero_ (void);
158
157 159
158/** 160/**
159 * Return absolute time of 0ms. 161 * Return absolute time of 0ms.
160 */ 162 */
161struct GNUNET_TIME_Absolute 163struct GNUNET_TIME_Absolute
162GNUNET_TIME_absolute_get_zero (void); 164GNUNET_TIME_absolute_get_zero_ (void);
165
163 166
164/** 167/**
165 * Return relative time of 1ms. 168 * Return relative time of 1ms.
166 */ 169 */
167struct GNUNET_TIME_Relative 170struct GNUNET_TIME_Relative
168GNUNET_TIME_relative_get_unit (void); 171GNUNET_TIME_relative_get_unit_ (void);
172
173
174/**
175 * Return relative time of 1s.
176 */
177struct GNUNET_TIME_Relative
178GNUNET_TIME_relative_get_second_ (void);
179
180
181/**
182 * Return relative time of 1 minute.
183 */
184struct GNUNET_TIME_Relative
185GNUNET_TIME_relative_get_minute_ (void);
186
187
188/**
189 * Return relative time of 1 hour.
190 */
191struct GNUNET_TIME_Relative
192GNUNET_TIME_relative_get_hour_ (void);
193
169 194
170/** 195/**
171 * Return "forever". 196 * Return "forever".
172 */ 197 */
173struct GNUNET_TIME_Relative 198struct GNUNET_TIME_Relative
174GNUNET_TIME_relative_get_forever (void); 199GNUNET_TIME_relative_get_forever_ (void);
200
175 201
176/** 202/**
177 * Return "forever". 203 * Return "forever".
178 */ 204 */
179struct GNUNET_TIME_Absolute 205struct GNUNET_TIME_Absolute
180GNUNET_TIME_absolute_get_forever (void); 206GNUNET_TIME_absolute_get_forever_ (void);
207
181 208
182/** 209/**
183 * Get the current time. 210 * Get the current time.
@@ -187,6 +214,7 @@ GNUNET_TIME_absolute_get_forever (void);
187struct GNUNET_TIME_Absolute 214struct GNUNET_TIME_Absolute
188GNUNET_TIME_absolute_get (void); 215GNUNET_TIME_absolute_get (void);
189 216
217
190/** 218/**
191 * Convert relative time to an absolute time in the 219 * Convert relative time to an absolute time in the
192 * future. 220 * future.
@@ -197,6 +225,7 @@ GNUNET_TIME_absolute_get (void);
197struct GNUNET_TIME_Absolute 225struct GNUNET_TIME_Absolute
198GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel); 226GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel);
199 227
228
200/** 229/**
201 * Return the minimum of two relative time values. 230 * Return the minimum of two relative time values.
202 * 231 *
@@ -209,6 +238,7 @@ GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1,
209 struct GNUNET_TIME_Relative t2); 238 struct GNUNET_TIME_Relative t2);
210 239
211 240
241
212/** 242/**
213 * Return the maximum of two relative time values. 243 * Return the maximum of two relative time values.
214 * 244 *
@@ -220,6 +250,7 @@ struct GNUNET_TIME_Relative
220GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, 250GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
221 struct GNUNET_TIME_Relative t2); 251 struct GNUNET_TIME_Relative t2);
222 252
253
223/** 254/**
224 * Return the minimum of two absolute time values. 255 * Return the minimum of two absolute time values.
225 * 256 *
@@ -231,6 +262,7 @@ struct GNUNET_TIME_Absolute
231GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, 262GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1,
232 struct GNUNET_TIME_Absolute t2); 263 struct GNUNET_TIME_Absolute t2);
233 264
265
234/** 266/**
235 * Return the maximum of two absolute time values. 267 * Return the maximum of two absolute time values.
236 * 268 *
@@ -242,6 +274,7 @@ struct GNUNET_TIME_Absolute
242GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, 274GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
243 struct GNUNET_TIME_Absolute t2); 275 struct GNUNET_TIME_Absolute t2);
244 276
277
245/** 278/**
246 * Given a timestamp in the future, how much time 279 * Given a timestamp in the future, how much time
247 * remains until then? 280 * remains until then?
@@ -281,6 +314,7 @@ struct GNUNET_TIME_Relative
281GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, 314GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start,
282 struct GNUNET_TIME_Absolute end); 315 struct GNUNET_TIME_Absolute end);
283 316
317
284/** 318/**
285 * Get the duration of an operation as the 319 * Get the duration of an operation as the
286 * difference of the current time and the given start time "hence". 320 * difference of the current time and the given start time "hence".
@@ -317,6 +351,7 @@ struct GNUNET_TIME_Absolute
317GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, 351GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
318 struct GNUNET_TIME_Relative duration); 352 struct GNUNET_TIME_Relative duration);
319 353
354
320/** 355/**
321 * Multiply relative time by a given factor. 356 * Multiply relative time by a given factor.
322 * 357 *
@@ -328,6 +363,7 @@ struct GNUNET_TIME_Relative
328GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, 363GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
329 unsigned int factor); 364 unsigned int factor);
330 365
366
331/** 367/**
332 * Divide relative time by a given factor. 368 * Divide relative time by a given factor.
333 * 369 *
@@ -339,6 +375,7 @@ struct GNUNET_TIME_Relative
339GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, 375GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
340 unsigned int factor); 376 unsigned int factor);
341 377
378
342/** 379/**
343 * Add relative times together. 380 * Add relative times together.
344 * 381 *
@@ -350,6 +387,7 @@ struct GNUNET_TIME_Relative
350GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, 387GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1,
351 struct GNUNET_TIME_Relative a2); 388 struct GNUNET_TIME_Relative a2);
352 389
390
353/** 391/**
354 * Subtract relative timestamp from the other. 392 * Subtract relative timestamp from the other.
355 * 393 *
@@ -371,6 +409,7 @@ GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1,
371struct GNUNET_TIME_RelativeNBO 409struct GNUNET_TIME_RelativeNBO
372GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a); 410GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a);
373 411
412
374/** 413/**
375 * Convert relative time from network byte order. 414 * Convert relative time from network byte order.
376 * 415 *
@@ -380,6 +419,7 @@ GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a);
380struct GNUNET_TIME_Relative 419struct GNUNET_TIME_Relative
381GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a); 420GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a);
382 421
422
383/** 423/**
384 * Convert relative time to network byte order. 424 * Convert relative time to network byte order.
385 * 425 *
@@ -389,6 +429,7 @@ GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a);
389struct GNUNET_TIME_AbsoluteNBO 429struct GNUNET_TIME_AbsoluteNBO
390GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a); 430GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a);
391 431
432
392/** 433/**
393 * Convert relative time from network byte order. 434 * Convert relative time from network byte order.
394 * 435 *
@@ -398,6 +439,7 @@ GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a);
398struct GNUNET_TIME_Absolute 439struct GNUNET_TIME_Absolute
399GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a); 440GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a);
400 441
442
401/** 443/**
402 * Convert a relative time to a string. 444 * Convert a relative time to a string.
403 * NOT reentrant! 445 * NOT reentrant!
@@ -409,6 +451,7 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a);
409const char * 451const char *
410GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time); 452GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time);
411 453
454
412/** 455/**
413 * Set the timestamp offset for this instance. 456 * Set the timestamp offset for this instance.
414 * 457 *
@@ -417,6 +460,7 @@ GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time);
417void 460void
418GNUNET_TIME_set_offset (long long offset); 461GNUNET_TIME_set_offset (long long offset);
419 462
463
420#if 0 /* keep Emacsens' auto-indent happy */ 464#if 0 /* keep Emacsens' auto-indent happy */
421{ 465{
422#endif 466#endif