| 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.hfa --
|
|---|
| 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 : Mon Mar 26 16:25:41 2018
|
|---|
| 13 | // Update Count : 11
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #pragma once
|
|---|
| 17 |
|
|---|
| 18 | #include <stdbool.h>
|
|---|
| 19 | #include <stdint.h>
|
|---|
| 20 |
|
|---|
| 21 | #include <assert.h>
|
|---|
| 22 |
|
|---|
| 23 | #include "time.hfa"
|
|---|
| 24 |
|
|---|
| 25 | #include "containers/list.hfa"
|
|---|
| 26 |
|
|---|
| 27 | struct $thread;
|
|---|
| 28 | struct processor;
|
|---|
| 29 |
|
|---|
| 30 | //=============================================================================================
|
|---|
| 31 | // Clock logic
|
|---|
| 32 | //=============================================================================================
|
|---|
| 33 |
|
|---|
| 34 | Time __kernel_get_time();
|
|---|
| 35 | void __kernel_set_timer( Duration alarm );
|
|---|
| 36 |
|
|---|
| 37 | //=============================================================================================
|
|---|
| 38 | // Alarm logic
|
|---|
| 39 | //=============================================================================================
|
|---|
| 40 |
|
|---|
| 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 |
|
|---|
| 47 | struct alarm_node_t {
|
|---|
| 48 | Duration initial; // time when alarm goes off
|
|---|
| 49 | Duration period; // if > 0 => period of alarm
|
|---|
| 50 |
|
|---|
| 51 | inline dlink(alarm_node_t);
|
|---|
| 52 |
|
|---|
| 53 | union {
|
|---|
| 54 | $thread * thrd; // thrd who created event
|
|---|
| 55 | processor * proc; // proc who created event
|
|---|
| 56 | Alarm_Callback callback; // callback to handle event
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 | Time timeval; // actual time at which the alarm goes off
|
|---|
| 60 | enum alarm_type type; // true if this is not a user defined alarm
|
|---|
| 61 | bool set :1; // whether or not the alarm has be registered
|
|---|
| 62 | };
|
|---|
| 63 | P9_EMBEDDED( alarm_node_t, dlink(alarm_node_t) )
|
|---|
| 64 |
|
|---|
| 65 | void ?{}( alarm_node_t & this, $thread * thrd, Duration alarm, Duration period );
|
|---|
| 66 | void ?{}( alarm_node_t & this, processor * proc, Duration alarm, Duration period );
|
|---|
| 67 | void ?{}( alarm_node_t & this, Alarm_Callback callback, Duration alarm, Duration period );
|
|---|
| 68 | void ^?{}( alarm_node_t & this );
|
|---|
| 69 |
|
|---|
| 70 | typedef dlist(alarm_node_t) alarm_list_t;
|
|---|
| 71 |
|
|---|
| 72 | void insert( alarm_list_t * this, alarm_node_t * n );
|
|---|
| 73 | alarm_node_t * pop( alarm_list_t * this );
|
|---|
| 74 |
|
|---|
| 75 | void register_self ( alarm_node_t * this );
|
|---|
| 76 | void unregister_self( alarm_node_t * this );
|
|---|
| 77 |
|
|---|
| 78 | // Local Variables: //
|
|---|
| 79 | // mode: c //
|
|---|
| 80 | // tab-width: 6 //
|
|---|
| 81 | // End: //
|
|---|