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

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 b69ea6b was b69ea6b, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Updated alarm to use bits/cfatime and fixed preemption for coroutines

  • Property mode set to 100644
File size: 3.9 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, zero_t zero ) { this.val = 0; }
51
52static inline __cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) {
53        this.val = 0;
54        return this;
55}
56
57// logical ops
58static inline bool ?==?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val == rhs.val; }
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; }
64
65static inline bool ?==?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val == rhs; }
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; }
71
72// addition/substract
73static 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
79static 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
85static inline __cfa_time_t ?`cfa_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
86static inline __cfa_time_t ?`cfa_ms( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; }
87static inline __cfa_time_t ?`cfa_us( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
88static inline __cfa_time_t ?`cfa_ns( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
89
90static inline __cfa_time_t from_s  ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
91static inline __cfa_time_t from_ms ( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; }
92static inline __cfa_time_t from_us ( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
93static inline __cfa_time_t from_ns ( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
Note: See TracBrowser for help on using the repository browser.