2 * Copyright (c) 2012 Your File System Inc. All rights reserved.
5 /* This header provides routines for dealing with the 100ns based AFS
6 * time type. We hide the actual variable behind a structure, so that
12 * ourTime = theirTime;
14 * will be caught by the compiler.
17 #ifndef OPENAFS_OPR_TIME_H
18 #define OPENAFS_OPR_TIME_H
25 opr_time_FromSecs(struct opr_time *out, time_t in)
27 out->time = ((afs_int64)in) * 10000000;
31 opr_time_ToSecs(struct opr_time *in)
33 return in->time/10000000;;
37 opr_time_FromMsecs(struct opr_time *out, int msecs)
39 out->time = ((afs_int64)msecs) * 10000;
43 opr_time_ToMsecs(struct opr_time *in)
45 return in->time/10000;
49 opr_time_FromTimeval(struct opr_time *out, struct timeval *in)
51 out->time = ((afs_int64)in->tv_sec) * 10000000 + in->tv_usec * 10;
55 opr_time_ToTimeval(struct opr_time *in, struct timeval *out)
57 out->tv_sec = in->time / 10000000;
58 out->tv_usec = (in->time / 10) % 1000000;
62 opr_time_Now(struct opr_time *out)
67 code = gettimeofday(&tv, NULL);
69 opr_time_FromTimeval(out, &tv);
75 opr_time_GreaterThan(struct opr_time *t1, struct opr_time *t2)
77 return t1->time > t2->time;
81 opr_time_LessThan(struct opr_time *t1, struct opr_time *t2)
83 return t1->time < t2->time;
87 opr_time_Add(struct opr_time *t1, struct opr_time *t2)
93 opr_time_Sub(struct opr_time *t1, struct opr_time *t2)
99 opr_time_AddMsec(struct opr_time *t1, int msec)
103 opr_time_FromMsecs(&t2, msec);
104 opr_time_Add(t1, &t2);