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 | // kernel -- |
---|
9 | // |
---|
10 | // Author : Thierry Delisle |
---|
11 | // Created On : Tue Jan 17 12:27:26 2017 |
---|
12 | // Last Modified By : Thierry Delisle |
---|
13 | // Last Modified On : -- |
---|
14 | // Update Count : 0 |
---|
15 | // |
---|
16 | |
---|
17 | #ifndef KERNEL_H |
---|
18 | #define KERNEL_H |
---|
19 | |
---|
20 | #include <stdbool.h> |
---|
21 | |
---|
22 | #include "invoke.h" |
---|
23 | |
---|
24 | extern "C" { |
---|
25 | #include <pthread.h> |
---|
26 | } |
---|
27 | |
---|
28 | //----------------------------------------------------------------------------- |
---|
29 | // Locks |
---|
30 | bool try_lock( spinlock * ); |
---|
31 | void lock( spinlock * ); |
---|
32 | void unlock( spinlock * ); |
---|
33 | |
---|
34 | struct signal_once { |
---|
35 | volatile bool cond; |
---|
36 | struct spinlock lock; |
---|
37 | struct __thread_queue_t blocked; |
---|
38 | }; |
---|
39 | |
---|
40 | void ?{}(signal_once * this); |
---|
41 | void ^?{}(signal_once * this); |
---|
42 | |
---|
43 | void wait( signal_once * ); |
---|
44 | void signal( signal_once * ); |
---|
45 | |
---|
46 | //----------------------------------------------------------------------------- |
---|
47 | // Cluster |
---|
48 | struct cluster { |
---|
49 | __thread_queue_t ready_queue; |
---|
50 | spinlock lock; |
---|
51 | }; |
---|
52 | |
---|
53 | void ?{}(cluster * this); |
---|
54 | void ^?{}(cluster * this); |
---|
55 | |
---|
56 | //----------------------------------------------------------------------------- |
---|
57 | // Processor |
---|
58 | enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule }; |
---|
59 | |
---|
60 | //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI) |
---|
61 | struct FinishAction { |
---|
62 | FinishOpCode action_code; |
---|
63 | thread_desc * thrd; |
---|
64 | spinlock * lock; |
---|
65 | spinlock ** locks; |
---|
66 | unsigned short lock_count; |
---|
67 | thread_desc ** thrds; |
---|
68 | unsigned short thrd_count; |
---|
69 | }; |
---|
70 | static inline void ?{}(FinishAction * this) { |
---|
71 | this->action_code = No_Action; |
---|
72 | this->thrd = NULL; |
---|
73 | this->lock = NULL; |
---|
74 | } |
---|
75 | static inline void ^?{}(FinishAction * this) {} |
---|
76 | |
---|
77 | struct processor { |
---|
78 | struct processorCtx_t * runner; |
---|
79 | cluster * cltr; |
---|
80 | coroutine_desc * current_coroutine; |
---|
81 | thread_desc * current_thread; |
---|
82 | pthread_t kernel_thread; |
---|
83 | |
---|
84 | signal_once terminated; |
---|
85 | volatile bool is_terminated; |
---|
86 | |
---|
87 | struct FinishAction finish; |
---|
88 | |
---|
89 | struct alarm_node_t * preemption_alarm; |
---|
90 | unsigned int preemption; |
---|
91 | |
---|
92 | bool pending_preemption; |
---|
93 | |
---|
94 | char * last_enable; |
---|
95 | }; |
---|
96 | |
---|
97 | void ?{}(processor * this); |
---|
98 | void ?{}(processor * this, cluster * cltr); |
---|
99 | void ^?{}(processor * this); |
---|
100 | |
---|
101 | #endif //KERNEL_H |
---|
102 | |
---|
103 | // Local Variables: // |
---|
104 | // mode: CFA // |
---|
105 | // tab-width: 6 // |
---|
106 | // End: // |
---|