File: time.h

package info (click to toggle)
iwd 3.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,112 kB
  • sloc: ansic: 140,705; sh: 4,960; makefile: 714
file content (66 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download | duplicates (11)
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
58
59
60
61
62
63
64
65
66
/*
 * Embedded Linux library
 * Copyright (C) 2019  Intel Corporation
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#ifndef __ELL_TIME_H
#define __ELL_TIME_H

#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

#define L_USEC_PER_SEC 1000000ULL
#define L_MSEC_PER_SEC 1000ULL
#define L_USEC_PER_MSEC 1000ULL
#define L_NSEC_PER_SEC  1000000000ULL
#define L_NSEC_PER_MSEC 1000000ULL
#define L_NSEC_PER_USEC 1000ULL
#define L_TIME_INVALID ((uint64_t) -1)

uint64_t l_time_now(void);

static inline bool l_time_after(uint64_t a, uint64_t b)
{
	return a > b;
}

static inline bool l_time_before(uint64_t a, uint64_t b)
{
	return l_time_after(b, a);
}

static inline uint64_t l_time_offset(uint64_t time, uint64_t offset)
{
	/* check overflow */
	if (offset > UINT64_MAX - time)
		return UINT64_MAX;

	return time + offset;
}

static inline uint64_t l_time_diff(uint64_t a, uint64_t b)
{
	return (a < b) ? b - a : a - b;
}

static inline uint64_t l_time_to_secs(uint64_t time)
{
	return time / L_USEC_PER_SEC;
}

static inline uint64_t l_time_to_msecs(uint64_t time)
{
	return time / L_USEC_PER_MSEC;
}

#ifdef __cplusplus
}
#endif

#endif /* __ELL_TIME_H */