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