1/* Copyright 2016 Google Inc.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. */
14
15#ifndef NSYNC_PUBLIC_NSYNC_TIME_H_
16#define NSYNC_PUBLIC_NSYNC_TIME_H_
17
18#include "nsync_cpp.h"
19#include "nsync_time_internal.h"
20
21/* The type nsync_time represents the interval elapsed between two moments in
22 time. Often the first such moment is an address-space-wide epoch, such as
23 the Unix epoch, but clients should not rely on the epoch in one address
24 space being the same as that in another. Intervals relative to the epoch
25 are known as absolute times.
26
27 The internals of nsync_time should be treated as opaque by clients.
28 See nsync_time_internal.h. */
29
30NSYNC_CPP_START_
31
32extern const nsync_time nsync_time_no_deadline; /* A deadline infinitely far in the future. */
33extern const nsync_time nsync_time_zero; /* The zero delay, or an expired deadline. */
34
35nsync_time nsync_time_now (void); /* Return the current time since the epoch. */
36
37/* Sleep for the specified delay. Returns the unslept time
38 which may be non-zero if the call was interrupted. */
39nsync_time nsync_time_sleep (nsync_time delay);
40
41/* Return a+b */
42nsync_time nsync_time_add (nsync_time a, nsync_time b);
43
44/* Return a-b */
45nsync_time nsync_time_sub (nsync_time a, nsync_time b);
46
47/* Return +ve, 0, or -ve according to whether a>b, a==b, or a<b. */
48int nsync_time_cmp (nsync_time a, nsync_time b);
49
50/* Return the specified number of milliseconds as a time. */
51nsync_time nsync_time_ms (unsigned ms);
52
53/* Return the specified number of microseconds as a time. */
54nsync_time nsync_time_us (unsigned us);
55
56/* Return an nsync_time constructed from second and nanosecond components */
57nsync_time nsync_time_s_ns (time_t s, unsigned ns);
58
59NSYNC_CPP_END_
60
61#endif /*NSYNC_PUBLIC_NSYNC_TIME_H_*/
62