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

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 3175147 was 969b3fe, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

More clean-up of the kernel code

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