Commit | Line | Data |
---|---|---|
0a531de6 GB |
1 | /* |
2 | Copyright (C) 2024 by Intra2net AG | |
3 | ||
4 | The software in this package is distributed under the GNU General | |
5 | Public License version 2 (with a special exception described below). | |
6 | ||
7 | A copy of GNU General Public License (GPL) is included in this distribution, | |
8 | in the file COPYING.GPL. | |
9 | ||
10 | As a special exception, if other files instantiate templates or use macros | |
11 | or inline functions from this file, or you compile this file and link it | |
12 | with other works to produce a work based on this file, this file | |
13 | does not by itself cause the resulting work to be covered | |
14 | by the GNU General Public License. | |
15 | ||
16 | However the source code for this file must still be made available | |
17 | in accordance with section (3) of the GNU General Public License. | |
18 | ||
19 | This exception does not invalidate any other reasons why a work based | |
20 | on this file might be covered by the GNU General Public License. | |
21 | */ | |
22 | ||
23 | #include <time.h> | |
24 | ||
25 | #include "monotonic_clock.hxx" | |
26 | ||
27 | /** | |
28 | * @brief fetches the value from the monotonic clock source. | |
29 | * @param[out] seconds the seconds. | |
30 | * @param[out] nano_seconds the nano seconds. | |
31 | * @return @a true if the clock was successfully read. | |
32 | */ | |
33 | bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds) | |
34 | { | |
35 | struct timespec tp[1]; | |
36 | int res= clock_gettime (CLOCK_MONOTONIC, tp); | |
37 | if (0 == res) | |
38 | { | |
39 | seconds= tp->tv_sec; | |
40 | nano_seconds= tp->tv_nsec; | |
41 | } | |
42 | return (res==0); | |
43 | } | |
44 | ||
45 | /** | |
46 | * @brief fetches the value from the monotonic clock source. | |
47 | * @return the time since system start in seconds, 0 if read was unsuccessful | |
48 | */ | |
49 | int monotonic_clock_gettime_sec() | |
50 | { | |
51 | long int seconds=0; | |
52 | long int nano_seconds; | |
53 | ||
54 | monotonic_clock_gettime(seconds,nano_seconds); | |
55 | return seconds; | |
56 | } |