-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathticks.h
More file actions
58 lines (47 loc) · 1.23 KB
/
Copy pathticks.h
File metadata and controls
58 lines (47 loc) · 1.23 KB
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
#pragma once
#include <stdint.h>
#ifndef TICKS_WIDTH
#define TICKS_WIDTH 32
#endif
#if TICKS_WIDTH == 64
typedef uint64_t ticks_t;
typedef int64_t dticks_t;
#define TICKS_MAX INT64_MAX
#elif TICKS_WIDTH == 32
typedef uint32_t ticks_t;
typedef int32_t dticks_t;
#define TICKS_MAX INT32_MAX
#elif TICKS_WIDTH == 16
typedef uint16_t ticks_t;
typedef int16_t dticks_t;
#define TICKS_MAX INT16_MAX
#elif TICKS_WIDTH == 8
typedef uint8_t ticks_t;
typedef int8_t dticks_t;
#define TICKS_MAX INT8_MAX
#else
#error "unknown ticks width"
#endif
#if !defined(TICKS_PER_MS) && !defined(MS_PER_TICK)
#define TICKS_PER_MS 1
#define MS_PER_TICK 1
#endif
#if defined(TICKS_PER_MS)
#define MS_TO_TICKS(ms) ((ms) * (TICKS_PER_MS))
#elif defined(MS_PER_TICK)
#define MS_TO_TICKS(ms) (((ms) + ((MS_PER_TICK) / 2)) / (MS_PER_TICK))
#else
#error "TICKS_PER_MS or MS_PER_TICK not defined"
#endif
#if defined(MS_PER_TICK)
#define TICKS_TO_MS(ticks) ((ticks) * (MS_PER_TICK))
#elif defined(TICKS_PER_MS)
#define TICKS_TO_MS(ticks) (((ticks) + ((TICKS_PER_MS) / 2)) / (TICKS_PER_MS))
#else
#error "TICKS_PER_MS or MS_PER_TICK not defined"
#endif
ticks_t ticks_now(void);
static inline ticks_t ticks_elapsed(ticks_t ts)
{
return ticks_now() - ts;
}