| 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 |
|
|---|
| 20 | #include <stdbool.h>
|
|---|
| 21 |
|
|---|
| 22 | #include "assert"
|
|---|
| 23 |
|
|---|
| 24 | typedef unsigned long int __cfa_time_t;
|
|---|
| 25 |
|
|---|
| 26 | struct thread_desc;
|
|---|
| 27 | struct processor;
|
|---|
| 28 |
|
|---|
| 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 |
|
|---|
| 42 | struct alarm_node_t {
|
|---|
| 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
|
|---|
| 46 |
|
|---|
| 47 | union {
|
|---|
| 48 | thread_desc * thrd; // thrd who created event
|
|---|
| 49 | processor * proc; // proc who created event
|
|---|
| 50 | };
|
|---|
| 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
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | typedef alarm_node_t ** __alarm_it_t;
|
|---|
| 57 |
|
|---|
| 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 );
|
|---|
| 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 |
|
|---|
| 75 | void register_self ( alarm_node_t * this );
|
|---|
| 76 | void unregister_self( alarm_node_t * this );
|
|---|
| 77 |
|
|---|
| 78 | #endif
|
|---|
| 79 |
|
|---|
| 80 | // Local Variables: //
|
|---|
| 81 | // mode: CFA //
|
|---|
| 82 | // tab-width: 6 //
|
|---|
| 83 | // End: //
|
|---|