[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 | // |
---|
[73abe95] | 7 | // alarm.hfa -- |
---|
[6cff9f3] | 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Fri Jun 2 11:31:25 2017 |
---|
[91c389a] | 11 | // Last Modified By : Peter A. Buhr |
---|
[2a84d06d] | 12 | // Last Modified On : Mon Mar 26 16:25:41 2018 |
---|
| 13 | // Update Count : 11 |
---|
[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 | |
---|
[58b6d1b] | 23 | #include "time.hfa" |
---|
[b69ea6b] | 24 | |
---|
[1eb239e4] | 25 | #include "containers/list.hfa" |
---|
[d3ab183] | 26 | |
---|
[ac2b598] | 27 | struct $thread; |
---|
[6cff9f3] | 28 | struct processor; |
---|
| 29 | |
---|
[969b3fe] | 30 | //============================================================================================= |
---|
| 31 | // Clock logic |
---|
| 32 | //============================================================================================= |
---|
[c81ebf9] | 33 | |
---|
[2a84d06d] | 34 | Time __kernel_get_time(); |
---|
| 35 | void __kernel_set_timer( Duration alarm ); |
---|
[c81ebf9] | 36 | |
---|
| 37 | //============================================================================================= |
---|
| 38 | // Alarm logic |
---|
| 39 | //============================================================================================= |
---|
| 40 | |
---|
[eeb5023] | 41 | enum alarm_type{ Kernel = 0, User = 1, Callback = 2 }; |
---|
| 42 | |
---|
| 43 | struct alarm_node_t; |
---|
| 44 | |
---|
| 45 | typedef void (*Alarm_Callback)(alarm_node_t & ); |
---|
| 46 | |
---|
[6cff9f3] | 47 | struct alarm_node_t { |
---|
[2a84d06d] | 48 | Time alarm; // time when alarm goes off |
---|
| 49 | Duration period; // if > 0 => period of alarm |
---|
[d3ab183] | 50 | |
---|
| 51 | DLISTED_MGD_IMPL_IN(alarm_node_t) |
---|
[6cff9f3] | 52 | |
---|
| 53 | union { |
---|
[4aeaee5] | 54 | $thread * thrd; // thrd who created event |
---|
| 55 | processor * proc; // proc who created event |
---|
| 56 | Alarm_Callback callback; // callback to handle event |
---|
[6cff9f3] | 57 | }; |
---|
[c81ebf9] | 58 | |
---|
| 59 | bool set :1; // whether or not the alarm has be registered |
---|
[eeb5023] | 60 | enum alarm_type type; // true if this is not a user defined alarm |
---|
[6cff9f3] | 61 | }; |
---|
[d3ab183] | 62 | DLISTED_MGD_IMPL_OUT(alarm_node_t) |
---|
[6cff9f3] | 63 | |
---|
[ac2b598] | 64 | void ?{}( alarm_node_t & this, $thread * thrd, Time alarm, Duration period ); |
---|
[2a84d06d] | 65 | void ?{}( alarm_node_t & this, processor * proc, Time alarm, Duration period ); |
---|
[4aeaee5] | 66 | void ?{}( alarm_node_t & this, Alarm_Callback callback, Time alarm, Duration period ); |
---|
[242a902] | 67 | void ^?{}( alarm_node_t & this ); |
---|
[6cff9f3] | 68 | |
---|
[d3ab183] | 69 | typedef dlist(alarm_node_t, alarm_node_t) alarm_list_t; |
---|
[6cff9f3] | 70 | |
---|
| 71 | void insert( alarm_list_t * this, alarm_node_t * n ); |
---|
| 72 | alarm_node_t * pop( alarm_list_t * this ); |
---|
| 73 | |
---|
[c81ebf9] | 74 | void register_self ( alarm_node_t * this ); |
---|
| 75 | void unregister_self( alarm_node_t * this ); |
---|
| 76 | |
---|
[6cff9f3] | 77 | // Local Variables: // |
---|
[6b0b624] | 78 | // mode: c // |
---|
[6cff9f3] | 79 | // tab-width: 6 // |
---|
[242a902] | 80 | // End: // |
---|