[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> |
---|
| 21 | |
---|
[6cff9f3] | 22 | #include "assert" |
---|
| 23 | |
---|
[c81ebf9] | 24 | typedef unsigned long int __cfa_time_t; |
---|
[6cff9f3] | 25 | |
---|
| 26 | struct thread_desc; |
---|
| 27 | struct processor; |
---|
| 28 | |
---|
[c81ebf9] | 29 | //============================================================================================= |
---|
| 30 | // Clock logic |
---|
| 31 | //============================================================================================= |
---|
| 32 | |
---|
| 33 | #define TIMEGRAN 1_000_000_000L // nanosecond granularity, except for timeval |
---|
| 34 | |
---|
| 35 | __cfa_time_t __kernel_get_time(); |
---|
| 36 | void __kernel_set_timer( __cfa_time_t alarm ); |
---|
| 37 | |
---|
| 38 | //============================================================================================= |
---|
| 39 | // Alarm logic |
---|
| 40 | //============================================================================================= |
---|
| 41 | |
---|
[6cff9f3] | 42 | struct alarm_node_t { |
---|
[c81ebf9] | 43 | __cfa_time_t alarm; // time when alarm goes off |
---|
| 44 | __cfa_time_t period; // if > 0 => period of alarm |
---|
| 45 | alarm_node_t * next; // intrusive link list field |
---|
[6cff9f3] | 46 | |
---|
| 47 | union { |
---|
| 48 | thread_desc * thrd; // thrd who created event |
---|
| 49 | processor * proc; // proc who created event |
---|
| 50 | }; |
---|
[c81ebf9] | 51 | |
---|
| 52 | bool set :1; // whether or not the alarm has be registered |
---|
| 53 | bool kernel_alarm :1; // true if this is not a user defined alarm |
---|
[6cff9f3] | 54 | }; |
---|
| 55 | |
---|
| 56 | typedef alarm_node_t ** __alarm_it_t; |
---|
| 57 | |
---|
[c81ebf9] | 58 | void ?{}( alarm_node_t * this, thread_desc * thrd, __cfa_time_t alarm = 0, __cfa_time_t period = 0 ); |
---|
| 59 | void ?{}( alarm_node_t * this, processor * proc, __cfa_time_t alarm = 0, __cfa_time_t period = 0 ); |
---|
| 60 | void ^?{}( alarm_node_t * this ); |
---|
[6cff9f3] | 61 | |
---|
| 62 | struct alarm_list_t { |
---|
| 63 | alarm_node_t * head; |
---|
| 64 | __alarm_it_t tail; |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | static inline void ?{}( alarm_list_t * this ) { |
---|
| 68 | this->head = 0; |
---|
| 69 | this->tail = &this->head; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | void insert( alarm_list_t * this, alarm_node_t * n ); |
---|
| 73 | alarm_node_t * pop( alarm_list_t * this ); |
---|
| 74 | |
---|
[c81ebf9] | 75 | void register_self ( alarm_node_t * this ); |
---|
| 76 | void unregister_self( alarm_node_t * this ); |
---|
| 77 | |
---|
[6cff9f3] | 78 | #endif |
---|
| 79 | |
---|
| 80 | // Local Variables: // |
---|
| 81 | // mode: CFA // |
---|
| 82 | // tab-width: 6 // |
---|
| 83 | // End: // |
---|