2 * Copyright (c) 2012 Your File System Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 /* This header provides routines for dealing with the 100ns based AFS
26 * time type. We hide the actual variable behind a structure, so that
32 * ourTime = theirTime;
34 * will be caught by the compiler.
37 #ifndef OPENAFS_OPR_TIME_H
38 #define OPENAFS_OPR_TIME_H
44 #define OPR_TIME_INIT {0LL}
47 opr_time_FromSecs(struct opr_time
*out
, time_t in
)
49 out
->time
= ((afs_int64
)in
) * 10000000;
53 opr_time_ToSecs(struct opr_time
*in
)
55 return in
->time
/10000000;;
59 opr_time_FromMsecs(struct opr_time
*out
, int msecs
)
61 out
->time
= ((afs_int64
)msecs
) * 10000;
65 opr_time_ToMsecs(struct opr_time
*in
)
67 return in
->time
/10000;
71 opr_time_FromTimeval(struct opr_time
*out
, struct timeval
*in
)
73 out
->time
= ((afs_int64
)in
->tv_sec
) * 10000000 + in
->tv_usec
* 10;
77 opr_time_ToTimeval(struct opr_time
*in
, struct timeval
*out
)
79 out
->tv_sec
= in
->time
/ 10000000;
80 out
->tv_usec
= (in
->time
/ 10) % 1000000;
84 opr_time_Now(struct opr_time
*out
)
89 code
= gettimeofday(&tv
, NULL
);
91 opr_time_FromTimeval(out
, &tv
);
97 opr_time_GreaterThan(struct opr_time
*t1
, struct opr_time
*t2
)
99 return t1
->time
> t2
->time
;
103 opr_time_LessThan(struct opr_time
*t1
, struct opr_time
*t2
)
105 return t1
->time
< t2
->time
;
109 opr_time_Add(struct opr_time
*t1
, struct opr_time
*t2
)
111 t1
->time
+= t2
->time
;
115 opr_time_Sub(struct opr_time
*t1
, struct opr_time
*t2
)
117 t1
->time
-= t2
->time
;
121 opr_time_AddMsec(struct opr_time
*t1
, int msec
)
125 opr_time_FromMsecs(&t2
, msec
);
126 opr_time_Add(t1
, &t2
);