This source file includes following definitions.
- lock_simh
- unlock_simh
- lock_libuv
- unlock_libuv
- test_libuv_lock
- get_rmw_lock
- lock_rmw
- lock_mem_rd
- lock_mem_wr
- unlock_rmw
- unlock_mem
- unlock_mem_force
- lock_ptr
- unlock_ptr
- lock_scu
- unlock_scu
- lock_iom
- unlock_iom
- lock_tst
- unlock_tst
- test_tst_lock
- pthread_create_with_cpu_policy
- createCPUThread
- stopCPUThread
- cpuRunningWait
- sleepCPU
- wakeCPU
- createIOMThread
- iomInterruptWait
- iomInterruptDone
- iomDoneWait
- setIOMInterrupt
- iomRdyWait
- createChnThread
- chnConnectWait
- chnConnectDone
- setChnConnect
- chnRdyWait
- initThreadz
- setSignals
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <signal.h>
24
25 #include "dps8.h"
26 #include "dps8_sys.h"
27 #include "dps8_cpu.h"
28 #include "dps8_faults.h"
29 #include "dps8_iom.h"
30 #include "dps8_utils.h"
31
32 #include "threadz.h"
33 #if defined(__FreeBSD__) || defined(__OpenBSD__)
34 # include <pthread_np.h>
35 #endif
36
37
38
39
40
41
42
43 #if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
44 pthread_cond_t iomCond;
45 pthread_mutex_t iom_start_lock;
46 #endif
47
48 #if !defined(QUIET_UNUSED)
49 void lock_simh (void)
50 {
51 pthread_mutex_lock (& simh_lock);
52 }
53
54 void unlock_simh (void)
55 {
56 pthread_mutex_unlock (& simh_lock);
57 }
58 #endif
59
60
61
62 static pthread_mutex_t libuv_lock;
63
64 void lock_libuv (void)
65 {
66 pthread_mutex_lock (& libuv_lock);
67 }
68
69 void unlock_libuv (void)
70 {
71 pthread_mutex_unlock (& libuv_lock);
72 }
73
74 #if defined(TESTING)
75 bool test_libuv_lock (void)
76 {
77
78 int rc;
79 rc = pthread_mutex_trylock (& libuv_lock);
80 if (rc)
81 {
82
83 return true;
84 }
85
86 rc = pthread_mutex_unlock (& libuv_lock);
87 if (rc)
88 sim_printf ("test_libuv_lock pthread_mutex_lock libuv_lock %d\n", rc);
89 return false;
90 }
91 #endif
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 #if !defined(LOCKLESS)
113 pthread_rwlock_t mem_lock = PTHREAD_RWLOCK_INITIALIZER;
114 static __thread bool have_mem_lock = false;
115 static __thread bool have_rmw_lock = false;
116
117 bool get_rmw_lock (void)
118 {
119 return have_rmw_lock;
120 }
121
122 void lock_rmw (void)
123 {
124 if (have_rmw_lock)
125 {
126 sim_warn ("%s: Already have RMW lock\n", __func__);
127 return;
128 }
129 if (have_mem_lock)
130 {
131 sim_warn ("%s: Already have memory lock\n", __func__);
132 return;
133 }
134 int rc= pthread_rwlock_wrlock (& mem_lock);
135 if (rc)
136 sim_printf ("%s pthread_rwlock_rdlock mem_lock %d\n", __func__, rc);
137 have_mem_lock = true;
138 have_rmw_lock = true;
139 }
140
141 void lock_mem_rd (void)
142 {
143
144 if (have_rmw_lock)
145 return;
146
147 if (have_mem_lock)
148 {
149 sim_warn ("%s: Already have memory lock\n", __func__);
150 return;
151 }
152 int rc= pthread_rwlock_rdlock (& mem_lock);
153 if (rc)
154 sim_printf ("%s pthread_rwlock_rdlock mem_lock %d\n", __func__, rc);
155 have_mem_lock = true;
156 }
157
158 void lock_mem_wr (void)
159 {
160
161 if (have_rmw_lock)
162 return;
163
164 if (have_mem_lock)
165 {
166 sim_warn ("%s: Already have memory lock\n", __func__);
167 return;
168 }
169 int rc= pthread_rwlock_wrlock (& mem_lock);
170 if (rc)
171 sim_printf ("%s pthread_rwlock_wrlock mem_lock %d\n", __func__, rc);
172 have_mem_lock = true;
173 }
174
175 void unlock_rmw (void)
176 {
177 if (! have_mem_lock)
178 {
179 sim_warn ("%s: Don't have memory lock\n", __func__);
180 return;
181 }
182 if (! have_rmw_lock)
183 {
184 sim_warn ("%s: Don't have RMW lock\n", __func__);
185 return;
186 }
187
188 int rc = pthread_rwlock_unlock (& mem_lock);
189 if (rc)
190 sim_printf ("%s pthread_rwlock_ublock mem_lock %d\n", __func__, rc);
191 have_mem_lock = false;
192 have_rmw_lock = false;
193 }
194
195 void unlock_mem (void)
196 {
197 if (have_rmw_lock)
198 return;
199 if (! have_mem_lock)
200 {
201 sim_warn ("%s: Don't have memory lock\n", __func__);
202 return;
203 }
204
205 int rc = pthread_rwlock_unlock (& mem_lock);
206 if (rc)
207 sim_printf ("%s pthread_rwlock_ublock mem_lock %d\n", __func__, rc);
208 have_mem_lock = false;
209 }
210
211 void unlock_mem_force (void)
212 {
213 if (have_mem_lock)
214 {
215 int rc = pthread_rwlock_unlock (& mem_lock);
216 if (rc)
217 sim_printf ("%s pthread_rwlock_unlock mem_lock %d\n", __func__, rc);
218 }
219 have_mem_lock = false;
220 have_rmw_lock = false;
221 }
222 #endif
223
224
225
226 void lock_ptr (pthread_mutex_t * lock)
227 {
228 int rc;
229 rc = pthread_mutex_lock (lock);
230 if (rc)
231 sim_printf ("lock_ptr %d\n", rc);
232 }
233
234 void unlock_ptr (pthread_mutex_t * lock)
235 {
236
237 int rc;
238 rc = pthread_mutex_unlock (lock);
239 if (rc)
240 sim_printf ("unlock_ptr %d\n", rc);
241 }
242
243
244
245 static pthread_mutex_t scu_lock;
246
247 void lock_scu (void)
248 {
249
250 int rc;
251 rc = pthread_mutex_lock (& scu_lock);
252 if (rc)
253 sim_printf ("lock_scu pthread_spin_lock scu %d\n", rc);
254 }
255
256 void unlock_scu (void)
257 {
258
259 int rc;
260 rc = pthread_mutex_unlock (& scu_lock);
261 if (rc)
262 sim_printf ("unlock_scu pthread_spin_lock scu %d\n", rc);
263 }
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286 static pthread_mutex_t iom_lock;
287
288 void lock_iom (void)
289 {
290 int rc;
291 rc = pthread_mutex_lock (& iom_lock);
292 if (rc)
293 sim_printf ("%s pthread_spin_lock iom %d\n", __func__, rc);
294 }
295
296 void unlock_iom (void)
297 {
298 int rc;
299 rc = pthread_mutex_unlock (& iom_lock);
300 if (rc)
301 sim_printf ("%s pthread_spin_lock iom %d\n", __func__, rc);
302 }
303
304
305
306 #if defined(TESTING)
307 static pthread_mutex_t tst_lock = PTHREAD_MUTEX_INITIALIZER;
308
309 void lock_tst (void)
310 {
311
312 int rc;
313 rc = pthread_mutex_lock (& tst_lock);
314 if (rc)
315 sim_printf ("lock_tst pthread_mutex_lock tst_lock %d\n", rc);
316 }
317
318 void unlock_tst (void)
319 {
320
321 int rc;
322 rc = pthread_mutex_unlock (& tst_lock);
323 if (rc)
324 sim_printf ("unlock_tst pthread_mutex_lock tst_lock %d\n", rc);
325 }
326
327
328
329 bool test_tst_lock (void)
330 {
331
332 int rc;
333 rc = pthread_mutex_trylock (& tst_lock);
334 if (rc)
335 {
336
337 return true;
338 }
339
340 rc = pthread_mutex_unlock (& tst_lock);
341 if (rc)
342 sim_printf ("test_tst_lock pthread_mutex_lock tst_lock %d\n", rc);
343 return false;
344 }
345 #endif
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373 struct cpuThreadz_t cpuThreadz [N_CPU_UNITS_MAX];
374
375
376
377 #if defined(__APPLE__)
378 int pthread_create_with_cpu_policy(
379 pthread_t *restrict thread,
380 int policy_group,
381 const pthread_attr_t *restrict attr,
382 void *(*start_routine)(void *), void *restrict arg)
383 {
384 # if defined(TESTING)
385 sim_msg ("\rAffinity policy group %d requested for thread.\r\n", policy_group);
386 # endif
387 thread_affinity_policy_data_t policy_data = { policy_group };
388 int rv = pthread_create_suspended_np(thread, attr, start_routine, arg);
389 mach_port_t mach_thread = pthread_mach_thread_np(*thread);
390 if (rv != 0)
391 {
392 return rv;
393 }
394 thread_policy_set(
395 mach_thread,
396 THREAD_AFFINITY_POLICY,
397 (thread_policy_t)&policy_data,
398 THREAD_AFFINITY_POLICY_COUNT);
399 thread_resume(mach_thread);
400 return 0;
401 }
402 #endif
403
404
405
406 void createCPUThread (uint cpuNum)
407 {
408 int rc;
409 struct cpuThreadz_t * p = & cpuThreadz[cpuNum];
410 if (p->run)
411 return;
412 cpu_reset_unit_idx (cpuNum, false);
413 p->cpuThreadArg = (int) cpuNum;
414
415 rc = pthread_mutex_init (& p->runLock, NULL);
416 if (rc)
417 sim_printf ("createCPUThread pthread_mutex_init runLock %d\n", rc);
418 rc = pthread_cond_init (& p->runCond, NULL);
419 if (rc)
420 sim_printf ("createCPUThread pthread_cond_init runCond %d\n", rc);
421
422 p->run = true;
423
424
425 #if defined(USE_MONOTONIC)
426 # if defined(__APPLE__) || !defined(CLOCK_MONOTONIC)
427 p->sleepClock = CLOCK_REALTIME;
428 rc = pthread_cond_init (& p->sleepCond, NULL);
429 # else
430 rc = pthread_condattr_init (& p->sleepCondAttr);
431 if (rc)
432 sim_printf ("createCPUThread pthread_condattr_init sleepCond %d\n", rc);
433
434 rc = pthread_condattr_setclock (& p->sleepCondAttr, CLOCK_MONOTONIC);
435 if (rc) {
436
437 p->sleepClock = CLOCK_REALTIME;
438 } else {
439 p->sleepClock = CLOCK_MONOTONIC;
440 }
441 # endif
442 rc = pthread_cond_init (& p->sleepCond, & p->sleepCondAttr);
443 #else
444 rc = pthread_cond_init (& p->sleepCond, NULL);
445 #endif
446 if (rc)
447 sim_printf ("createCPUThread pthread_cond_init sleepCond %d\n", rc);
448
449 #if defined(__APPLE__)
450 rc = pthread_create_with_cpu_policy(
451 & p->cpuThread,
452 cpuNum,
453 NULL,
454 cpu_thread_main,
455 & p->cpuThreadArg);
456 #else
457 rc = pthread_create(
458 & p->cpuThread,
459 NULL,
460 cpu_thread_main,
461 & p->cpuThreadArg);
462 #endif
463 if (rc)
464 sim_printf ("createCPUThread pthread_create %d\n", rc);
465
466 #if defined(AFFINITY)
467 if (cpus[cpuNum].set_affinity)
468 {
469 cpu_set_t cpuset;
470 CPU_ZERO (& cpuset);
471 CPU_SET (cpus[cpuNum].affinity, & cpuset);
472 int s = pthread_setaffinity_np (p->cpuThread, sizeof (cpu_set_t), & cpuset);
473 if (s)
474 sim_printf ("pthread_setaffinity_np %u on CPU %u returned %d\n",
475 cpus[cpuNum].affinity, cpuNum, s);
476 }
477 #endif
478 }
479
480 void stopCPUThread(void)
481 {
482 struct cpuThreadz_t * p = & cpuThreadz[current_running_cpu_idx];
483 p->run = false;
484 pthread_exit(NULL);
485 }
486
487
488
489 #if defined(THREADZ)
490 void cpuRunningWait (void)
491 {
492 int rc;
493 struct cpuThreadz_t * p = & cpuThreadz[current_running_cpu_idx];
494 if (p->run)
495 return;
496 rc = pthread_mutex_lock (& p->runLock);
497 if (rc)
498 sim_printf ("cpuRunningWait pthread_mutex_lock %d\n", rc);
499 while (! p->run)
500 {
501 rc = pthread_cond_wait (& p->runCond, & p->runLock);
502 if (rc)
503 sim_printf ("cpuRunningWait pthread_cond_wait %d\n", rc);
504 }
505 rc = pthread_mutex_unlock (& p->runLock);
506 if (rc)
507 sim_printf ("cpuRunningWait pthread_mutex_unlock %d\n", rc);
508 }
509 #endif
510
511
512
513 unsigned long sleepCPU (unsigned long usec) {
514 int rc;
515 struct cpuThreadz_t * p = & cpuThreadz[current_running_cpu_idx];
516 struct timespec startTime, absTime;
517
518 #if defined(USE_MONOTONIC)
519 clock_gettime (p->sleepClock, & startTime);
520 #else
521 clock_gettime (CLOCK_REALTIME, & startTime);
522 #endif
523 absTime = startTime;
524 int64_t nsec = ((int64_t) usec) * 1000L + (int64_t)startTime.tv_nsec;
525 absTime.tv_nsec = nsec % 1000000000L;
526 absTime.tv_sec += nsec / 1000000000L;
527
528 rc = pthread_cond_timedwait (& p->sleepCond, & scu_lock, & absTime);
529
530 if (rc == ETIMEDOUT) {
531 return 0;
532 }
533
534 if (rc) {
535 cpu_state_t * cpup = _cpup;
536 sim_printf ("sleepCPU pthread_cond_timedwait rc %ld usec %ld TR %lu CPU %lu\n",
537 (long) rc, (long) usec, (unsigned long) cpu.rTR,
538 (unsigned long) current_running_cpu_idx);
539 }
540
541 struct timespec newTime;
542 struct timespec delta;
543 #if defined(USE_MONOTONIC)
544 clock_gettime (p->sleepClock, & newTime);
545 #else
546 clock_gettime (CLOCK_REALTIME, & newTime);
547 #endif
548 timespec_diff (& absTime, & newTime, & delta);
549
550 if (delta.tv_nsec < 0)
551 return 0;
552 return (unsigned long) delta.tv_nsec / 1000L;
553 }
554
555
556
557 void wakeCPU (uint cpuNum)
558 {
559 int rc;
560 struct cpuThreadz_t * p = & cpuThreadz[cpuNum];
561
562 rc = pthread_cond_signal (& p->sleepCond);
563 if (rc)
564 sim_printf ("wakeCPU pthread_cond_signal %d\n", rc);
565 }
566
567 #if defined(IO_THREADZ)
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591 struct iomThreadz_t iomThreadz [N_IOM_UNITS_MAX];
592
593
594
595 void createIOMThread (uint iomNum)
596 {
597 int rc;
598 struct iomThreadz_t * p = & iomThreadz[iomNum];
599 # if defined(tdbg)
600 p->inCnt = 0;
601 p->outCnt = 0;
602 # endif
603 p->iomThreadArg = (int) iomNum;
604
605 p->ready = false;
606
607 p->intr = false;
608 rc = pthread_mutex_init (& p->intrLock, NULL);
609 if (rc)
610 sim_printf ("createIOMThread pthread_mutex_init intrLock %d\n", rc);
611 rc = pthread_cond_init (& p->intrCond, NULL);
612 if (rc)
613 sim_printf ("createIOMThread pthread_cond_init intrCond %d\n", rc);
614
615 # if defined(__APPLE__)
616 rc = pthread_create_with_cpu_policy(
617 & p->iomThread,
618 iomNum,
619 NULL,
620 iom_thread_main,
621 & p->iomThreadArg);
622 # else
623 rc = pthread_create(
624 & p->iomThread,
625 NULL,
626 iom_thread_main,
627 & p->iomThreadArg);
628 # endif
629 if (rc)
630 sim_printf ("createIOMThread pthread_create %d\n", rc);
631 }
632
633
634
635 void iomInterruptWait (void)
636 {
637 int rc;
638 struct iomThreadz_t * p = & iomThreadz[this_iom_idx];
639 rc = pthread_mutex_lock (& p->intrLock);
640 if (rc)
641 sim_printf ("iomInterruptWait pthread_mutex_lock %d\n", rc);
642 p -> ready = true;
643 while (! p->intr)
644 {
645 rc = pthread_cond_wait (& p->intrCond, & p->intrLock);
646 if (rc)
647 sim_printf ("iomInterruptWait pthread_cond_wait %d\n", rc);
648 }
649 # if defined(tdbg)
650 p->outCnt++;
651 if (p->inCnt != p->outCnt)
652 sim_printf ("iom thread %d in %d out %d\n", this_iom_idx,
653 p->inCnt, p->outCnt);
654 # endif
655 }
656
657
658
659 void iomInterruptDone (void)
660 {
661 int rc;
662 struct iomThreadz_t * p = & iomThreadz[this_iom_idx];
663 p->intr = false;
664 rc = pthread_cond_signal (& p->intrCond);
665 if (rc)
666 sim_printf ("iomInterruptDone pthread_cond_signal %d\n", rc);
667 rc = pthread_mutex_unlock (& p->intrLock);
668 if (rc)
669 sim_printf ("iomInterruptDone pthread_mutex_unlock %d\n", rc);
670 }
671
672
673
674 void iomDoneWait (uint iomNum)
675 {
676 int rc;
677 struct iomThreadz_t * p = & iomThreadz[iomNum];
678 rc = pthread_mutex_lock (& p->intrLock);
679 if (rc)
680 sim_printf ("iomDoneWait pthread_mutex_lock %d\n", rc);
681 while (p->intr)
682 {
683 rc = pthread_cond_wait (& p->intrCond, & p->intrLock);
684 if (rc)
685 sim_printf ("iomDoneWait pthread_cond_wait %d\n", rc);
686 }
687 rc = pthread_mutex_unlock (& p->intrLock);
688 if (rc)
689 sim_printf ("iomDoneWait pthread_mutex_unlock %d\n", rc);
690 }
691
692
693
694 void setIOMInterrupt (uint iomNum)
695 {
696 int rc;
697 struct iomThreadz_t * p = & iomThreadz[iomNum];
698 rc = pthread_mutex_lock (& p->intrLock);
699 if (rc)
700 sim_printf ("setIOMInterrupt pthread_mutex_lock %d\n", rc);
701 while (p->intr)
702 {
703 rc = pthread_cond_wait(&p->intrCond, &p->intrLock);
704 if (rc)
705 sim_printf ("setIOMInterrupt pthread_cond_wait intrLock %d\n", rc);
706 }
707 # if defined(tdbg)
708 p->inCnt++;
709 # endif
710 p->intr = true;
711 rc = pthread_cond_signal (& p->intrCond);
712 if (rc)
713 sim_printf ("setIOMInterrupt pthread_cond_signal %d\n", rc);
714 rc = pthread_mutex_unlock (& p->intrLock);
715 if (rc)
716 sim_printf ("setIOMInterrupt pthread_mutex_unlock %d\n", rc);
717 }
718
719
720
721 void iomRdyWait (uint iomNum)
722 {
723 struct iomThreadz_t * p = & iomThreadz[iomNum];
724 while (! p -> ready)
725 sim_usleep (10000);
726 }
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750 struct chnThreadz_t chnThreadz [N_IOM_UNITS_MAX] [MAX_CHANNELS];
751
752
753
754 void createChnThread (uint iomNum, uint chnNum, const char * devTypeStr)
755 {
756 int rc;
757 struct chnThreadz_t * p = & chnThreadz[iomNum][chnNum];
758 p->chnThreadArg = (int) (chnNum + iomNum * MAX_CHANNELS);
759
760 # if defined(tdbg)
761 p->inCnt = 0;
762 p->outCnt = 0;
763 # endif
764 p->ready = false;
765
766 p->connect = false;
767 rc = pthread_mutex_init (& p->connectLock, NULL);
768 if (rc)
769 sim_printf ("createChnThread pthread_mutex_init connectLock %d\n", rc);
770 rc = pthread_cond_init (& p->connectCond, NULL);
771 if (rc)
772 sim_printf ("createChnThread pthread_cond_init connectCond %d\n", rc);
773
774 # if defined(__APPLE__)
775 rc = pthread_create_with_cpu_policy(
776 & p->chnThread,
777 iomNum
778 NULL,
779 chan_thread_main,
780 & p->chnThreadArg);
781 # else
782 rc = pthread_create(
783 & p->chnThread,
784 NULL,
785 chan_thread_main,
786 & p->chnThreadArg);
787 # endif
788 if (rc)
789 sim_printf ("createChnThread pthread_create %d\n", rc);
790 }
791
792
793
794 void chnConnectWait (void)
795 {
796 int rc;
797 struct chnThreadz_t * p = & chnThreadz[this_iom_idx][this_chan_num];
798
799 rc = pthread_mutex_lock (& p->connectLock);
800 if (rc)
801 sim_printf ("chnConnectWait pthread_mutex_lock %d\n", rc);
802 p -> ready = true;
803 while (! p->connect)
804 {
805 rc = pthread_cond_wait (& p->connectCond, & p->connectLock);
806 if (rc)
807 sim_printf ("chnConnectWait pthread_cond_wait %d\n", rc);
808 }
809 # if defined(tdbg)
810 p->outCnt++;
811 if (p->inCnt != p->outCnt)
812 sim_printf ("chn thread %d in %d out %d\n", this_chan_num,
813 p->inCnt, p->outCnt);
814 # endif
815 }
816
817
818
819 void chnConnectDone (void)
820 {
821 int rc;
822 struct chnThreadz_t * p = & chnThreadz[this_iom_idx][this_chan_num];
823 p->connect = false;
824 rc = pthread_cond_signal (& p->connectCond);
825 if (rc)
826 sim_printf ("chnInterruptDone pthread_cond_signal %d\n", rc);
827 rc = pthread_mutex_unlock (& p->connectLock);
828 if (rc)
829 sim_printf ("chnConnectDone pthread_mutex_unlock %d\n", rc);
830 }
831
832
833
834 void setChnConnect (uint iomNum, uint chnNum)
835 {
836 int rc;
837 struct chnThreadz_t * p = & chnThreadz[iomNum][chnNum];
838 rc = pthread_mutex_lock (& p->connectLock);
839 if (rc)
840 sim_printf ("setChnConnect pthread_mutex_lock %d\n", rc);
841 while (p->connect)
842 {
843 rc = pthread_cond_wait(&p->connectCond, &p->connectLock);
844 if (rc)
845 sim_printf ("setChnInterrupt pthread_cond_wait connectLock %d\n", rc);
846 }
847 # if defined(tdbg)
848 p->inCnt++;
849 # endif
850 p->connect = true;
851 rc = pthread_cond_signal (& p->connectCond);
852 if (rc)
853 sim_printf ("setChnConnect pthread_cond_signal %d\n", rc);
854 rc = pthread_mutex_unlock (& p->connectLock);
855 if (rc)
856 sim_printf ("setChnConnect pthread_mutex_unlock %d\n", rc);
857 }
858
859
860
861 void chnRdyWait (uint iomNum, uint chnNum)
862 {
863 struct chnThreadz_t * p = & chnThreadz[iomNum][chnNum];
864 while (! p -> ready)
865 sim_usleep (10000);
866 }
867 #endif
868
869 void initThreadz (void)
870 {
871 #if defined(IO_THREADZ)
872
873 (void)memset (chnThreadz, 0, sizeof (chnThreadz));
874 #endif
875
876 #if !defined(LOCKLESS)
877
878 have_mem_lock = false;
879 have_rmw_lock = false;
880 #endif
881 #if defined(__FreeBSD__) || defined(__OpenBSD__)
882 pthread_mutexattr_t scu_attr;
883 pthread_mutexattr_init(&scu_attr);
884 # if !defined(__OpenBSD__)
885 pthread_mutexattr_settype(&scu_attr, PTHREAD_MUTEX_ADAPTIVE_NP);
886 # endif
887 pthread_mutex_init (& scu_lock, &scu_attr);
888 #else
889 pthread_mutex_init (& scu_lock, NULL);
890 #endif
891 pthread_mutexattr_t iom_attr;
892 pthread_mutexattr_init(& iom_attr);
893 pthread_mutexattr_settype(& iom_attr, PTHREAD_MUTEX_RECURSIVE);
894
895 pthread_mutex_init (& iom_lock, & iom_attr);
896
897 pthread_mutexattr_t libuv_attr;
898 pthread_mutexattr_init(& libuv_attr);
899 pthread_mutexattr_settype(& libuv_attr, PTHREAD_MUTEX_RECURSIVE);
900
901 pthread_mutex_init (& libuv_lock, & libuv_attr);
902
903 #if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
904 pthread_cond_init (& iomCond, NULL);
905 pthread_mutex_init (& iom_start_lock, NULL);
906 #endif
907 }
908
909
910
911 void int_handler (int signal);
912
913 void setSignals (void)
914 {
915 #if !defined(__MINGW64__) && !defined(__MINGW32__)
916 struct sigaction act;
917 (void)memset (& act, 0, sizeof (act));
918 act.sa_handler = int_handler;
919 act.sa_flags = 0;
920 sigaction (SIGINT, & act, NULL);
921 sigaction (SIGTERM, & act, NULL);
922 #endif
923 }
924
925
926
927
928
929
930
931
932
933
934