2 * Copyright (C) 2006 Rackable Systems All rights reserved.
4 * This file is part of LVM2.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU Lesser General Public License v.2.1.
10 * You should have received a copy of the GNU Lesser General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * Abstract out the time methods used so they can be adjusted later -
17 * the results of these routines should stay in-core. This implementation
24 #include "timestamp.h"
27 * The realtime section uses clock_gettime with the CLOCK_MONOTONIC
28 * parameter to prevent issues with time warps
33 #include <bits/time.h>
39 struct timestamp *get_timestamp(void)
41 struct timestamp *ts = NULL;
43 if (!(ts = dm_malloc(sizeof(*ts))))
46 if (clock_gettime(CLOCK_MONOTONIC, &ts->t)) {
47 log_sys_error("clock_gettime", "get_timestamp");
54 /* cmp_timestamp: Compare two timestamps
56 * Return: -1 if t1 is less than t2
57 * 0 if t1 is equal to t2
58 * 1 if t1 is greater than t2
60 int cmp_timestamp(struct timestamp *t1, struct timestamp *t2)
62 if(t1->t.tv_sec < t2->t.tv_sec)
64 if(t1->t.tv_sec > t2->t.tv_sec)
67 if(t1->t.tv_nsec < t2->t.tv_nsec)
69 if(t1->t.tv_nsec > t2->t.tv_nsec)
75 #else /* ! HAVE_REALTIME */
78 * The !realtime section just uses gettimeofday and is therefore subject
79 * to ntp-type time warps - not sure if should allow that.
88 struct timestamp *get_timestamp(void)
90 struct timestamp *ts = NULL;
92 if (!(ts = dm_malloc(sizeof(*ts))))
95 if (gettimeofday(&ts->t, NULL)) {
96 log_sys_error("gettimeofday", "get_timestamp");
103 /* cmp_timestamp: Compare two timestamps
105 * Return: -1 if t1 is less than t2
106 * 0 if t1 is equal to t2
107 * 1 if t1 is greater than t2
109 int cmp_timestamp(struct timestamp *t1, struct timestamp *t2)
111 if(t1->t.tv_sec < t2->t.tv_sec)
113 if(t1->t.tv_sec > t2->t.tv_sec)
116 if(t1->t.tv_usec < t2->t.tv_usec)
118 if(t1->t.tv_usec > t2->t.tv_usec)
124 #endif /* HAVE_REALTIME */
126 void destroy_timestamp(struct timestamp *t)