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
24 #define OPR_TIME_INIT {0LL}
27 opr_time_FromSecs(struct opr_time *out, time_t in)
29 out->time = ((afs_int64)in) * 10000000;
33 opr_time_ToSecs(struct opr_time *in)
35 return in->time/10000000;;
39 opr_time_FromMsecs(struct opr_time *out, int msecs)
41 out->time = ((afs_int64)msecs) * 10000;
45 opr_time_ToMsecs(struct opr_time *in)
47 return in->time/10000;
51 opr_time_FromTimeval(struct opr_time *out, struct timeval *in)
53 out->time = ((afs_int64)in->tv_sec) * 10000000 + in->tv_usec * 10;
57 opr_time_ToTimeval(struct opr_time *in, struct timeval *out)
59 out->tv_sec = in->time / 10000000;
60 out->tv_usec = (in->time / 10) % 1000000;
64 opr_time_Now(struct opr_time *out)
69 code = gettimeofday(&tv, NULL);
71 opr_time_FromTimeval(out, &tv);
77 opr_time_GreaterThan(struct opr_time *t1, struct opr_time *t2)
79 return t1->time > t2->time;
83 opr_time_LessThan(struct opr_time *t1, struct opr_time *t2)
85 return t1->time < t2->time;
89 opr_time_Add(struct opr_time *t1, struct opr_time *t2)
95 opr_time_Sub(struct opr_time *t1, struct opr_time *t2)
101 opr_time_AddMsec(struct opr_time *t1, int msec)
105 opr_time_FromMsecs(&t2, msec);
106 opr_time_Add(t1, &t2);