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