1 | //
|
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
|
---|
3 | //
|
---|
4 | // The contents of this file are covered under the licence agreement in the
|
---|
5 | // file "LICENCE" distributed with Cforall.
|
---|
6 | //
|
---|
7 | // align.h --
|
---|
8 | //
|
---|
9 | // Author : Thierry Delisle
|
---|
10 | // Created On : Mon Feb 12 18:06:59 2018
|
---|
11 | // Last Modified By :
|
---|
12 | // Last Modified On :
|
---|
13 | // Update Count : 0
|
---|
14 | //
|
---|
15 | // This library is free software; you can redistribute it and/or modify it
|
---|
16 | // under the terms of the GNU Lesser General Public License as published by the
|
---|
17 | // Free Software Foundation; either version 2.1 of the License, or (at your
|
---|
18 | // option) any later version.
|
---|
19 | //
|
---|
20 | // This library is distributed in the hope that it will be useful, but WITHOUT
|
---|
21 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
22 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
---|
23 | // for more details.
|
---|
24 | //
|
---|
25 | // You should have received a copy of the GNU Lesser General Public License
|
---|
26 | // along with this library.
|
---|
27 | //
|
---|
28 |
|
---|
29 | #pragma once
|
---|
30 |
|
---|
31 | extern "C" {
|
---|
32 | #include <time.h>
|
---|
33 | }
|
---|
34 |
|
---|
35 | #include "bits/defs.h"
|
---|
36 |
|
---|
37 | struct timespec;
|
---|
38 | struct itimerval;
|
---|
39 |
|
---|
40 | //=============================================================================================
|
---|
41 | // time type
|
---|
42 | //=============================================================================================
|
---|
43 |
|
---|
44 | struct __cfa_time_t {
|
---|
45 | uint64_t val;
|
---|
46 | };
|
---|
47 |
|
---|
48 | // ctors
|
---|
49 | static inline void ?{}( __cfa_time_t & this ) { this.val = 0; }
|
---|
50 | static inline void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
|
---|
51 |
|
---|
52 | static inline __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) {
|
---|
53 | this.val = 0;
|
---|
54 | return this;
|
---|
55 | }
|
---|
56 |
|
---|
57 | // logical ops
|
---|
58 | static inline bool ?==?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val == rhs.val; }
|
---|
59 | static inline bool ?!=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val != rhs.val; }
|
---|
60 | static inline bool ?>? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val > rhs.val; }
|
---|
61 | static inline bool ?<? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val < rhs.val; }
|
---|
62 | static inline bool ?>=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >= rhs.val; }
|
---|
63 | static inline bool ?<=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <= rhs.val; }
|
---|
64 |
|
---|
65 | static inline bool ?==?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val == rhs; }
|
---|
66 | static inline bool ?!=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val != rhs; }
|
---|
67 | static inline bool ?>? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val > rhs; }
|
---|
68 | static inline bool ?<? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val < rhs; }
|
---|
69 | static inline bool ?>=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >= rhs; }
|
---|
70 | static inline bool ?<=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <= rhs; }
|
---|
71 |
|
---|
72 | // addition/substract
|
---|
73 | static inline __cfa_time_t ?+?( __cfa_time_t lhs, __cfa_time_t rhs ) {
|
---|
74 | __cfa_time_t ret;
|
---|
75 | ret.val = lhs.val + rhs.val;
|
---|
76 | return ret;
|
---|
77 | }
|
---|
78 |
|
---|
79 | static inline __cfa_time_t ?-?( __cfa_time_t lhs, __cfa_time_t rhs ) {
|
---|
80 | __cfa_time_t ret;
|
---|
81 | ret.val = lhs.val - rhs.val;
|
---|
82 | return ret;
|
---|
83 | }
|
---|
84 |
|
---|
85 | static inline __cfa_time_t ?`cfa_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
|
---|
86 | static inline __cfa_time_t ?`cfa_ms( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000ul; return ret; }
|
---|
87 | static inline __cfa_time_t ?`cfa_us( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000ul; return ret; }
|
---|
88 | static inline __cfa_time_t ?`cfa_ns( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1ul; return ret; }
|
---|
89 |
|
---|
90 | static inline __cfa_time_t from_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
|
---|
91 | static inline __cfa_time_t from_ms ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000ul; return ret; }
|
---|
92 | static inline __cfa_time_t from_us ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000ul; return ret; }
|
---|
93 | static inline __cfa_time_t from_ns ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1ul; return ret; }
|
---|