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 | void lock( spinlock * ); |
---|
31 | void unlock( spinlock * ); |
---|
32 | |
---|
33 | struct signal_once { |
---|
34 | volatile bool cond; |
---|
35 | struct spinlock lock; |
---|
36 | struct __thread_queue_t blocked; |
---|
37 | }; |
---|
38 | |
---|
39 | void ?{}(signal_once * this); |
---|
40 | void ^?{}(signal_once * this); |
---|
41 | |
---|
42 | void wait( signal_once * ); |
---|
43 | void signal( signal_once * ); |
---|
44 | |
---|
45 | //----------------------------------------------------------------------------- |
---|
46 | // Cluster |
---|
47 | struct cluster { |
---|
48 | __thread_queue_t ready_queue; |
---|
49 | spinlock lock; |
---|
50 | }; |
---|
51 | |
---|
52 | void ?{}(cluster * this); |
---|
53 | void ^?{}(cluster * this); |
---|
54 | |
---|
55 | //----------------------------------------------------------------------------- |
---|
56 | // Processor |
---|
57 | enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule }; |
---|
58 | |
---|
59 | //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI) |
---|
60 | struct FinishAction { |
---|
61 | FinishOpCode action_code; |
---|
62 | thread_desc * thrd; |
---|
63 | spinlock * lock; |
---|
64 | spinlock ** locks; |
---|
65 | unsigned short lock_count; |
---|
66 | thread_desc ** thrds; |
---|
67 | unsigned short thrd_count; |
---|
68 | }; |
---|
69 | static inline void ?{}(FinishAction * this) { |
---|
70 | this->action_code = No_Action; |
---|
71 | this->thrd = NULL; |
---|
72 | this->lock = NULL; |
---|
73 | } |
---|
74 | static inline void ^?{}(FinishAction * this) {} |
---|
75 | |
---|
76 | struct processor { |
---|
77 | struct processorCtx_t * runner; |
---|
78 | cluster * cltr; |
---|
79 | coroutine_desc * current_coroutine; |
---|
80 | thread_desc * current_thread; |
---|
81 | pthread_t kernel_thread; |
---|
82 | |
---|
83 | signal_once terminated; |
---|
84 | volatile bool is_terminated; |
---|
85 | |
---|
86 | struct FinishAction finish; |
---|
87 | }; |
---|
88 | |
---|
89 | void ?{}(processor * this); |
---|
90 | void ?{}(processor * this, cluster * cltr); |
---|
91 | void ^?{}(processor * this); |
---|
92 | |
---|
93 | #endif //KERNEL_H |
---|
94 | |
---|
95 | // Local Variables: // |
---|
96 | // mode: c // |
---|
97 | // tab-width: 4 // |
---|
98 | // End: // |
---|