summaryrefslogtreecommitdiff
path: root/src/common/clock.c
blob: e1f917afb60fd7be7c1da79c556e822c0f4a5811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 1996, 2012 Oracle and/or its affiliates.  All rights reserved.
 *
 * $Id$
 */

#include "db_config.h"

#include "db_int.h"
/*
 * __clock_set_expires --
 *	Set the expire time given the time to live.
 *
 * PUBLIC: void __clock_set_expires __P((ENV *, db_timespec *, db_timeout_t));
 */
void
__clock_set_expires(env, timespecp, timeout)
	ENV *env;
	db_timespec *timespecp;
	db_timeout_t timeout;
{
	db_timespec v;

	/*
	 * If timespecp is set then it contains "now".  This avoids repeated
	 * system calls to get the time.
	 */
	if (!timespecisset(timespecp))
		__os_gettime(env, timespecp, 1);

	/* Convert the microsecond timeout argument to a timespec. */
	DB_TIMEOUT_TO_TIMESPEC(timeout, &v);

	/* Add the timeout to "now". */
	timespecadd(timespecp, &v);
}

/*
 * __clock_expired -- determine if a timeout has expired.
 *
 * PUBLIC: int __clock_expired __P((ENV *, db_timespec *, db_timespec *));
 */
int
__clock_expired(env, now, timespecp)
	ENV *env;
	db_timespec *now, *timespecp;
{
	if (!timespecisset(timespecp))
		return (0);

	if (!timespecisset(now))
		__os_gettime(env, now, 1);

	return (timespeccmp(now, timespecp, >=));
}