2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: SubTime - subtract two timevals from each other.
8 #include "timer_intern.h"
10 /*****************************************************************************
13 #include <devices/timer.h>
14 #include <proto/timer.h>
16 AROS_LH2(void, SubTime
,
19 AROS_LHA(struct timeval
*, dest
, A0
),
20 AROS_LHA(struct timeval
*, src
, A1
),
23 struct Device
*, TimerBase
, 8, Timer
)
26 SubTime() will subtract the src timeval from the destination
27 timeval, ie "dest - src --> dest".
30 dest - Destination timeval
34 The timeval dest will contain the sum (dest - src).
37 This function is safe to call from interrupts.
42 May not preserve registers.
50 18-02-1997 iaint Implemented.
52 *****************************************************************************/
55 AROS_LIBBASE_EXT_DECL(struct Device
*,TimerBase
)
57 /* Normalize the terms */
58 while(src
->tv_micro
> 999999)
61 src
->tv_micro
-= 1000000;
63 while(dest
->tv_micro
> 999999)
66 dest
->tv_micro
-= 1000000;
69 /* Check if wrap around will happen, when subtracting src->tv_micro
70 from dest->tv_micro. If yes, then normalize, by adding 1 sec to
71 micros and subtracting 1 sec from secs. Note: this check must be
72 done here, ie. before subtracting src timeval from dest timeval! */
74 if(dest
->tv_micro
< src
->tv_micro
)
76 dest
->tv_micro
+= 1000000;
80 dest
->tv_micro
-= src
->tv_micro
;
81 dest
->tv_secs
-= src
->tv_secs
;