source: src/libcfa/concurrency/alarm.h @ ed235b6

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 ed235b6 was 9236060, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Merge branch 'master' into references

  • Property mode set to 100644
File size: 4.1 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// alarm.h --
8//
9// Author           : Thierry Delisle
10// Created On       : Fri Jun 2 11:31:25 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat Jul 22 09:59:27 2017
13// Update Count     : 3
14//
15
16#pragma once
17
18#include <stdbool.h>
19#include <stdint.h>
20
21#include <assert.h>
22
23struct thread_desc;
24struct processor;
25
26struct timespec;
27struct itimerval;
28
29//=============================================================================================
30// time type
31//=============================================================================================
32
33struct __cfa_time_t {
34        uint64_t val;
35};
36
37// ctors
38void ?{}( __cfa_time_t & this );
39void ?{}( __cfa_time_t & this, zero_t zero );
40void ?{}( __cfa_time_t & this, timespec * curr );
41void ?{}( itimerval & this, __cfa_time_t * alarm );
42
43__cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs );
44
45// logical ops
46static inline bool ?==?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val == rhs.val; }
47static inline bool ?!=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val != rhs.val; }
48static inline bool ?>? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >  rhs.val; }
49static inline bool ?<? ( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <  rhs.val; }
50static inline bool ?>=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val >= rhs.val; }
51static inline bool ?<=?( __cfa_time_t lhs, __cfa_time_t rhs ) { return lhs.val <= rhs.val; }
52
53static inline bool ?==?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val == rhs; }
54static inline bool ?!=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val != rhs; }
55static inline bool ?>? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >  rhs; }
56static inline bool ?<? ( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <  rhs; }
57static inline bool ?>=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val >= rhs; }
58static inline bool ?<=?( __cfa_time_t lhs, zero_t rhs ) { return lhs.val <= rhs; }
59
60// addition/substract
61static inline __cfa_time_t ?+?( __cfa_time_t lhs, __cfa_time_t rhs ) {
62        __cfa_time_t ret;
63        ret.val = lhs.val + rhs.val;
64        return ret;
65}
66
67static inline __cfa_time_t ?-?( __cfa_time_t lhs, __cfa_time_t rhs ) {
68        __cfa_time_t ret;
69        ret.val = lhs.val - rhs.val;
70        return ret;
71}
72
73__cfa_time_t from_s ( uint64_t );
74__cfa_time_t from_ms( uint64_t );
75__cfa_time_t from_us( uint64_t );
76__cfa_time_t from_ns( uint64_t );
77
78extern __cfa_time_t zero_time;
79
80//=============================================================================================
81// Clock logic
82//=============================================================================================
83
84__cfa_time_t __kernel_get_time();
85void __kernel_set_timer( __cfa_time_t alarm );
86
87//=============================================================================================
88// Alarm logic
89//=============================================================================================
90
91struct alarm_node_t {
92        __cfa_time_t alarm;             // time when alarm goes off
93        __cfa_time_t period;            // if > 0 => period of alarm
94        alarm_node_t * next;            // intrusive link list field
95
96        union {
97                thread_desc * thrd;     // thrd who created event
98                processor * proc;               // proc who created event
99        };
100
101        bool set                :1;             // whether or not the alarm has be registered
102        bool kernel_alarm       :1;             // true if this is not a user defined alarm
103};
104
105typedef alarm_node_t ** __alarm_it_t;
106
107void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
108void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time );
109void ^?{}( alarm_node_t & this );
110
111struct alarm_list_t {
112        alarm_node_t * head;
113        __alarm_it_t tail;
114};
115
116static inline void ?{}( alarm_list_t & this ) {
117        this.head = 0;
118        this.tail = &this.head;
119}
120
121void insert( alarm_list_t * this, alarm_node_t * n );
122alarm_node_t * pop( alarm_list_t * this );
123
124void register_self  ( alarm_node_t * this );
125void unregister_self( alarm_node_t * this );
126
127// Local Variables: //
128// mode: c //
129// tab-width: 6 //
130// End: //
Note: See TracBrowser for help on using the repository browser.