The Pedigree Project  0.1
Time.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef TIME_H
21 #define TIME_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/types.h"
25 
26 namespace Time
27 {
28 typedef uint64_t Timestamp;
29 
30 namespace Multiplier
31 {
32 const Timestamp Nanosecond = 1U;
33 const Timestamp Microsecond = 1000U;
34 const Timestamp Millisecond = 1000000U;
35 const Timestamp Second = Millisecond * 1000U;
36 const Timestamp Minute = Second * 60U;
37 const Timestamp Hour = Minute * 60U;
38 const Timestamp Day = Hour * 24U;
39 
40 // slightly sanity check the above multiplications
41 static_assert(Microsecond == 1000, "Microsecond conversion multiplier to nanoseconds is incorrect.");
42 static_assert(Millisecond == 1000000, "Millisecond conversion multiplier to nanoseconds is incorrect.");
43 static_assert(Second == 1000000000, "Seconds conversion multiplier to nanoseconds is incorrect.");
44 } // namespace Multiplier
45 
47 const Timestamp Infinity = 0xFFFFFFFFFFFFFFFFULL;
48 
50 EXPORTED_PUBLIC bool delay(Timestamp nanoseconds);
51 
56 EXPORTED_PUBLIC void *addAlarm(Timestamp nanoseconds);
57 
59 EXPORTED_PUBLIC void removeAlarm(void *handle);
60 
62 EXPORTED_PUBLIC void
63 runAfter(int (*func)(void *), void *param, Timestamp nanoseconds);
64 
66 EXPORTED_PUBLIC Timestamp getTime(bool sync = false);
67 
69 EXPORTED_PUBLIC Timestamp getTimeNanoseconds(bool sync = false);
70 
75 EXPORTED_PUBLIC Timestamp getTicks();
76 
77 namespace Conversion
78 {
82 EXPORTED_PUBLIC Timestamp toUnix(
83  size_t second, size_t minute, size_t hour, size_t dom, size_t month,
84  size_t year);
85 
86 } // namespace Conversion
87 
88 } // namespace Time
89 
90 #endif
Definition: fat.h:143
Definition: Stopwatch.h:25