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