@@ -338,19 +338,6 @@ EXTERN volatile clock_t g_system_ticks;
338
338
#define timespec_to_tick (ts ) \
339
339
((clock_t)(ts)->tv_sec * TICK_PER_SEC + (ts)->tv_nsec / NSEC_PER_TICK)
340
340
341
- /****************************************************************************
342
- * Name: clock_timespec_compare
343
- *
344
- * Description:
345
- * Return < 0 if time ts1 is before time ts2
346
- * Return > 0 if time ts2 is before time ts1
347
- * Return 0 if time ts1 is the same as time ts2
348
- *
349
- ****************************************************************************/
350
-
351
- int clock_timespec_compare (FAR const struct timespec * ts1 ,
352
- FAR const struct timespec * ts2 );
353
-
354
341
/****************************************************************************
355
342
* Name: clock_timespec_add
356
343
*
@@ -366,9 +353,20 @@ int clock_timespec_compare(FAR const struct timespec *ts1,
366
353
*
367
354
****************************************************************************/
368
355
369
- void clock_timespec_add (FAR const struct timespec * ts1 ,
370
- FAR const struct timespec * ts2 ,
371
- FAR struct timespec * ts3 );
356
+ #define clock_timespec_add (ts1 , ts2 , ts3 ) \
357
+ do \
358
+ { \
359
+ time_t _sec = (ts1)->tv_sec + (ts2)->tv_sec; \
360
+ long _nsec = (ts1)->tv_nsec + (ts2)->tv_nsec; \
361
+ if (_nsec >= NSEC_PER_SEC) \
362
+ { \
363
+ _nsec -= NSEC_PER_SEC; \
364
+ _sec++; \
365
+ } \
366
+ (ts3)->tv_sec = _sec; \
367
+ (ts3)->tv_nsec = _nsec; \
368
+ }\
369
+ while (0)
372
370
373
371
/****************************************************************************
374
372
* Name: clock_timespec_subtract
@@ -386,9 +384,40 @@ void clock_timespec_add(FAR const struct timespec *ts1,
386
384
*
387
385
****************************************************************************/
388
386
389
- void clock_timespec_subtract (FAR const struct timespec * ts1 ,
390
- FAR const struct timespec * ts2 ,
391
- FAR struct timespec * ts3 );
387
+ #define clock_timespec_subtract (ts1 , ts2 , ts3 ) \
388
+ do \
389
+ { \
390
+ time_t _sec = (ts1)->tv_sec - (ts2)->tv_sec; \
391
+ long _nsec = (ts1)->tv_nsec - (ts2)->tv_nsec; \
392
+ if (_nsec < 0) \
393
+ { \
394
+ _nsec += NSEC_PER_SEC; \
395
+ _sec--; \
396
+ } \
397
+ if (_sec < 0) \
398
+ { \
399
+ _sec = 0; \
400
+ _nsec = 0; \
401
+ } \
402
+ (ts3)->tv_sec = _sec; \
403
+ (ts3)->tv_nsec = _nsec; \
404
+ }\
405
+ while (0)
406
+
407
+ /****************************************************************************
408
+ * Name: clock_timespec_compare
409
+ *
410
+ * Description:
411
+ * Return < 0 if time ts1 is before time ts2
412
+ * Return > 0 if time ts2 is before time ts1
413
+ * Return 0 if time ts1 is the same as time ts2
414
+ *
415
+ ****************************************************************************/
416
+
417
+ #define clock_timespec_compare (ts1 , ts2 ) \
418
+ (((ts1)->tv_sec < (ts2)->tv_sec) ? -1 : \
419
+ ((ts1)->tv_sec > (ts2)->tv_sec) ? 1 : \
420
+ (ts1)->tv_nsec - (ts2)->tv_nsec)
392
421
393
422
/****************************************************************************
394
423
* Name: clock_isleapyear
0 commit comments