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 void lock_iom (void);
126 void unlock_iom (void);
127
128
129 #if defined(TESTING)
130 void lock_tst (void);
131 void unlock_tst (void);
132 bool test_tst_lock (void);
133 #endif
134
135
136 struct cpuThreadz_t
137 {
138 pthread_t cpuThread;
139 int cpuThreadArg;
140
141
142 bool run;
143 pthread_cond_t runCond;
144 pthread_mutex_t runLock;
145
146
147 #if defined (USE_MONOTONIC)
148 # if !defined(__APPLE__) && defined (CLOCK_MONOTONIC)
149 clockid_t sleepClock;
150 pthread_condattr_t sleepCondAttr;
151 # endif
152 #endif
153 pthread_cond_t sleepCond;
154
155 };
156 extern struct cpuThreadz_t cpuThreadz [N_CPU_UNITS_MAX];
157
158 void createCPUThread (uint cpuNum);
159 void stopCPUThread(void);
160 #if defined(THREADZ)
161 void cpuRunningWait (void);
162 #endif
163 unsigned long sleepCPU (unsigned long usec);
164 void wakeCPU (uint cpuNum);
165
166 #if defined(IO_THREADZ)
167
168
169 struct iomThreadz_t
170 {
171 pthread_t iomThread;
172 int iomThreadArg;
173
174 volatile bool ready;
175
176
177 bool intr;
178 pthread_cond_t intrCond;
179 pthread_mutex_t intrLock;
180
181 # if defined(tdbg)
182
183 int inCnt;
184 int outCnt;
185 # endif
186 };
187 extern struct iomThreadz_t iomThreadz [N_IOM_UNITS_MAX];
188
189 void createIOMThread (uint iomNum);
190 void iomInterruptWait (void);
191 void iomInterruptDone (void);
192 void iomDoneWait (uint iomNum);
193 void setIOMInterrupt (uint iomNum);
194 void iomRdyWait (uint iomNum);
195
196
197
198 struct chnThreadz_t
199 {
200 bool started;
201
202 pthread_t chnThread;
203 int chnThreadArg;
204
205
206 volatile bool ready;
207
208
209 bool connect;
210 pthread_cond_t connectCond;
211 pthread_mutex_t connectLock;
212
213 # if defined(tdbg)
214
215 int inCnt;
216 int outCnt;
217 # endif
218 };
219 extern struct chnThreadz_t chnThreadz [N_IOM_UNITS_MAX] [MAX_CHANNELS];
220
221 void createChnThread (uint iomNum, uint chnNum, const char * devTypeStr);
222 void chnConnectWait (void);
223 void chnConnectDone (void);
224 void setChnConnect (uint iomNum, uint chnNum);
225 void chnRdyWait (uint iomNum, uint chnNum);
226 #endif
227
228 void initThreadz (void);
229 void setSignals (void);
230
231 #if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
232 extern pthread_cond_t iomCond;
233 extern pthread_mutex_t iom_start_lock;
234 #endif