1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #define tdbg
21
22 #define use_spinlock
23
24
25
26 #ifdef __APPLE__
27 # include <mach/mach.h>
28 # include <mach/mach_time.h>
29 #endif
30
31 #include <pthread.h>
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 #ifndef LOCKLESS
94 extern pthread_rwlock_t mem_lock;
95 #endif
96
97
98 void lock_ptr (pthread_mutex_t * lock);
99 void unlock_ptr (pthread_mutex_t * lock);
100
101
102 void lock_libuv (void);
103 void unlock_libuv (void);
104 bool test_libuv_lock (void);
105
106
107 #ifndef QUIET_UNUSED
108 void lock_simh (void);
109 void unlock_simh (void);
110 #endif
111
112
113 #ifndef LOCKLESS
114 bool get_rmw_lock (void);
115 void lock_rmw (void);
116 void lock_mem_rd (void);
117 void lock_mem_wr (void);
118 void unlock_rmw (void);
119 void unlock_mem (void);
120 void unlock_mem_force (void);
121 #endif
122
123
124 void lock_scu (void);
125 void unlock_scu (void);
126
127
128 void lock_iom (void);
129 void unlock_iom (void);
130
131
132 #ifdef TESTING
133 void lock_tst (void);
134 void unlock_tst (void);
135 bool test_tst_lock (void);
136 #endif
137
138 #ifdef __APPLE__
139 int rtsched_thread(pthread_t pthread);
140 #endif
141
142
143 struct cpuThreadz_t
144 {
145 pthread_t cpuThread;
146 int cpuThreadArg;
147
148
149 bool run;
150 pthread_cond_t runCond;
151 pthread_mutex_t runLock;
152
153
154 #ifdef USE_MONOTONIC
155 # if !defined __APPLE__ && defined (CLOCK_MONOTONIC)
156 clockid_t sleepClock;
157 pthread_condattr_t sleepCondAttr;
158 # endif
159 #endif
160 pthread_cond_t sleepCond;
161
162 };
163 extern struct cpuThreadz_t cpuThreadz [N_CPU_UNITS_MAX];
164
165 void createCPUThread (uint cpuNum);
166 void stopCPUThread(void);
167 #ifdef THREADZ
168 void cpuRunningWait (void);
169 #endif
170 unsigned long sleepCPU (unsigned long usec);
171 void wakeCPU (uint cpuNum);
172
173 #ifdef IO_THREADZ
174
175
176 struct iomThreadz_t
177 {
178 pthread_t iomThread;
179 int iomThreadArg;
180
181 volatile bool ready;
182
183
184 bool intr;
185 pthread_cond_t intrCond;
186 pthread_mutex_t intrLock;
187
188 # ifdef tdbg
189
190 int inCnt;
191 int outCnt;
192 # endif
193 };
194 extern struct iomThreadz_t iomThreadz [N_IOM_UNITS_MAX];
195
196 void createIOMThread (uint iomNum);
197 void iomInterruptWait (void);
198 void iomInterruptDone (void);
199 void iomDoneWait (uint iomNum);
200 void setIOMInterrupt (uint iomNum);
201 void iomRdyWait (uint iomNum);
202
203
204
205 struct chnThreadz_t
206 {
207 bool started;
208
209 pthread_t chnThread;
210 int chnThreadArg;
211
212
213 volatile bool ready;
214
215
216 bool connect;
217 pthread_cond_t connectCond;
218 pthread_mutex_t connectLock;
219
220 # ifdef tdbg
221
222 int inCnt;
223 int outCnt;
224 # endif
225 };
226 extern struct chnThreadz_t chnThreadz [N_IOM_UNITS_MAX] [MAX_CHANNELS];
227
228 void createChnThread (uint iomNum, uint chnNum, const char * devTypeStr);
229 void chnConnectWait (void);
230 void chnConnectDone (void);
231 void setChnConnect (uint iomNum, uint chnNum);
232 void chnRdyWait (uint iomNum, uint chnNum);
233
234 #endif
235
236 void initThreadz (void);
237 void setSignals (void);
238
239 #ifdef IO_ASYNC_PAYLOAD_CHAN_THREAD
240 extern pthread_cond_t iomCond;
241 extern pthread_mutex_t iom_start_lock;
242 #endif