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
159 };
160 extern struct cpuThreadz_t cpuThreadz [N_CPU_UNITS_MAX];
161
162 void createCPUThread (uint cpuNum);
163 void stopCPUThread(void);
164 #if defined(THREADZ)
165 void cpuRunningWait (void);
166 #endif
167 unsigned long sleepCPU (unsigned long usec);
168 void wakeCPU (uint cpuNum);
169
170 #if defined(IO_THREADZ)
171
172
173 struct iomThreadz_t
174 {
175 pthread_t iomThread;
176 int iomThreadArg;
177
178 volatile bool ready;
179
180
181 bool intr;
182 pthread_cond_t intrCond;
183 pthread_mutex_t intrLock;
184
185 # if defined(tdbg)
186
187 int inCnt;
188 int outCnt;
189 # endif
190 };
191 extern struct iomThreadz_t iomThreadz [N_IOM_UNITS_MAX];
192
193 void createIOMThread (uint iomNum);
194 void iomInterruptWait (void);
195 void iomInterruptDone (void);
196 void iomDoneWait (uint iomNum);
197 void setIOMInterrupt (uint iomNum);
198 void iomRdyWait (uint iomNum);
199
200
201
202 struct chnThreadz_t
203 {
204 bool started;
205
206 pthread_t chnThread;
207 int chnThreadArg;
208
209
210 volatile bool ready;
211
212
213 bool connect;
214 pthread_cond_t connectCond;
215 pthread_mutex_t connectLock;
216
217 # if defined(tdbg)
218
219 int inCnt;
220 int outCnt;
221 # endif
222 };
223 extern struct chnThreadz_t chnThreadz [N_IOM_UNITS_MAX] [MAX_CHANNELS];
224
225 void createChnThread (uint iomNum, uint chnNum, const char * devTypeStr);
226 void chnConnectWait (void);
227 void chnConnectDone (void);
228 void setChnConnect (uint iomNum, uint chnNum);
229 void chnRdyWait (uint iomNum, uint chnNum);
230 #endif
231
232 void initThreadz (void);
233 void setSignals (void);
234
235 #if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
236 extern pthread_cond_t iomCond;
237 extern pthread_mutex_t iom_start_lock;
238 #endif