source: src/libcfa/bits/cfatime.h @ d893266a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since d893266a was d8548e2, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Fixed preemption and changed default_preemption to use cfa_time_t

  • Property mode set to 100644
File size: 4.3 KB
Line 
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
31extern "C" {
32#include <time.h>
33}
34
35#include "bits/defs.h"
36
37struct timespec;
38struct itimerval;
39
40//=============================================================================================
41// time type
42//=============================================================================================
43
44struct __cfa_time_t {
45        uint64_t val;
46};
47
48// ctors
49static inline void ?{}( __cfa_time_t & this ) { this.val = 0; }
50static inline void ?{}( __cfa_time_t & this, const __cfa_time_t & rhs ) { this.val = rhs.val; }
51static inline void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
52
53static inline __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) {
54        this.val = 0;
55        return this;
56}
57
58// logical ops
59static inline bool ?==?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val == rhs.val; }
60static inline bool ?!=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val != rhs.val; }
61static inline bool ?>? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >  rhs.val; }
62static inline bool ?<? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <  rhs.val; }
63static inline bool ?>=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >= rhs.val; }
64static inline bool ?<=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <= rhs.val; }
65
66static inline bool ?==?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val == rhs; }
67static inline bool ?!=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val != rhs; }
68static inline bool ?>? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >  rhs; }
69static inline bool ?<? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <  rhs; }
70static inline bool ?>=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >= rhs; }
71static inline bool ?<=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <= rhs; }
72
73// addition/substract
74static inline __cfa_time_t ?+?( __cfa_time_t lhs, __cfa_time_t rhs ) {
75        __cfa_time_t ret;
76        ret.val = lhs.val + rhs.val;
77        return ret;
78}
79
80static inline __cfa_time_t ?-?( __cfa_time_t lhs, __cfa_time_t rhs ) {
81        __cfa_time_t ret;
82        ret.val = lhs.val - rhs.val;
83        return ret;
84}
85
86static inline __cfa_time_t ?`cfa_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
87static inline __cfa_time_t ?`cfa_ms( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; }
88static inline __cfa_time_t ?`cfa_us( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
89static inline __cfa_time_t ?`cfa_ns( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
90
91static inline __cfa_time_t from_s  ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
92static inline __cfa_time_t from_ms ( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; }
93static inline __cfa_time_t from_us ( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
94static inline __cfa_time_t from_ns ( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
95
96static inline uint64_t to_s  ( __cfa_time_t t ) { return t.val / 1_000_000_000ul; }
97static inline uint64_t to_ms ( __cfa_time_t t ) { return t.val /     1_000_000ul; }
98static inline uint64_t to_us ( __cfa_time_t t ) { return t.val /         1_000ul; }
99static inline uint64_t to_ns ( __cfa_time_t t ) { return t.val /             1ul; }
Note: See TracBrowser for help on using the repository browser.