source: src/libcfa/concurrency/alarm.h @ 396fd72

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 396fd72 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
RevLine 
[6cff9f3]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
[91c389a]11// Last Modified By : Peter A. Buhr
[6b0b624]12// Last Modified On : Sat Jul 22 09:59:27 2017
13// Update Count     : 3
[6cff9f3]14//
15
[6b0b624]16#pragma once
[6cff9f3]17
[c81ebf9]18#include <stdbool.h>
[8cb529e]19#include <stdint.h>
[c81ebf9]20
[91c389a]21#include <assert.h>
[6cff9f3]22
23struct thread_desc;
24struct processor;
25
[969b3fe]26struct timespec;
27struct itimerval;
28
[c81ebf9]29//=============================================================================================
[969b3fe]30// time type
[c81ebf9]31//=============================================================================================
32
[969b3fe]33struct __cfa_time_t {
34        uint64_t val;
35};
36
37// ctors
[9236060]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 );
[969b3fe]42
[9236060]43__cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs );
[969b3fe]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//=============================================================================================
[c81ebf9]83
84__cfa_time_t __kernel_get_time();
85void __kernel_set_timer( __cfa_time_t alarm );
86
87//=============================================================================================
88// Alarm logic
89//=============================================================================================
90
[6cff9f3]91struct alarm_node_t {
[c81ebf9]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
[6cff9f3]95
96        union {
97                thread_desc * thrd;     // thrd who created event
98                processor * proc;               // proc who created event
99        };
[c81ebf9]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
[6cff9f3]103};
104
105typedef alarm_node_t ** __alarm_it_t;
106
[9236060]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 );
[242a902]109void ^?{}( alarm_node_t & this );
[6cff9f3]110
111struct alarm_list_t {
112        alarm_node_t * head;
113        __alarm_it_t tail;
114};
115
[242a902]116static inline void ?{}( alarm_list_t & this ) {
117        this.head = 0;
118        this.tail = &this.head;
[6cff9f3]119}
120
121void insert( alarm_list_t * this, alarm_node_t * n );
122alarm_node_t * pop( alarm_list_t * this );
123
[c81ebf9]124void register_self  ( alarm_node_t * this );
125void unregister_self( alarm_node_t * this );
126
[6cff9f3]127// Local Variables: //
[6b0b624]128// mode: c //
[6cff9f3]129// tab-width: 6 //
[242a902]130// End: //
Note: See TracBrowser for help on using the repository browser.