Module Name: src Committed By: martin Date: Fri Jun 30 17:13:50 UTC 2023
Modified Files: src/external/cddl/osnet/dist/tools/ctf/cvt [netbsd-10]: barrier.c barrier.h ctfmerge.c tdata.c src/external/cddl/osnet/sys/sys [netbsd-10]: opentypes.h src/tools/compat [netbsd-10]: configure configure.ac nbtool_config.h.in Log Message: Pull up following revision(s) (requested by riastradh in ticket #221): external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c: revision 1.18 external/cddl/osnet/sys/sys/opentypes.h: revision 1.7 tools/compat/configure: revision 1.100 external/cddl/osnet/dist/tools/ctf/cvt/barrier.c: revision 1.6 external/cddl/osnet/dist/tools/ctf/cvt/barrier.h: revision 1.4 external/cddl/osnet/dist/tools/ctf/cvt/barrier.c: revision 1.7 external/cddl/osnet/dist/tools/ctf/cvt/barrier.c: revision 1.8 tools/compat/configure.ac: revision 1.100 external/cddl/osnet/dist/tools/ctf/cvt/tdata.c: revision 1.10 tools/compat/nbtool_config.h.in: revision 1.54 ctfmerge: error check sem_*() and pthread_*() APIs terminate() if sem_*() returns -1 or pthread_*() returns != 0. (Set errno from pthread_*() so terminate() prints the strerror message). Note: Failing on errors instead of ignoring them helps identify reasons for intermittent failures, such as those on macOS host builds: ERROR: nbctfmerge: barrier_init: sem_init(bar_sem): Function not implemented ctfmerge: fix macOS semaphore implementation Use dispatch_semaphore_create() if present instead of sem_init(). macOS doesn't actually implement sem_init() (et al) (even though it provides the prototypes as deprecated). This was detected by the previous commit to ctfmerge that added error handling. Implement ctfmerge's barrier operations in terms of dispatch(3) APIs such as dispatch_semaphore_create() (et al). Update tools/compat/configure.ac to find dispatch_semaphore_create(). Fixes ctfmerge on macOS hosts. Inspired by https://stackoverflow.com/a/27847103 tools/compat: regen for dispatch_semaphore_create ctfmerge: fix macOS semaphore implementation, part 2 dispatch_semaphore_signal() doesn't return an error, just an indicator of whether a thread was woken or not, so there's no need to fail on non-zero return. osnet: on macOS, use <mach/boolean.h> for boolean_t macOS/x86_64 defines boolean_t as 'unsigned int' not 'int', which causes a build issue with tools/ctfmerge on that host after my recent fixes for macOS semaphores. So use the <mach/boolean.h> instead of a local typedef ifdef __APPLE__. May fix a macOS/x86_64 build issue reported by cjep@. Builds fine on NetBSD/amd64 or macOS/arm. Note: this compat stuff is clunky, and based on the commit log, annoyingly error prone. A newer sync of osnet from upstream /may/ improve a lot of these compat typedef workarounds for solaris types... To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.5.10.1 \ src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.c cvs rdiff -u -r1.3 -r1.3.12.1 \ src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.h cvs rdiff -u -r1.17 -r1.17.8.1 \ src/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c cvs rdiff -u -r1.9 -r1.9.12.1 \ src/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c cvs rdiff -u -r1.6 -r1.6.6.1 src/external/cddl/osnet/sys/sys/opentypes.h cvs rdiff -u -r1.99 -r1.99.6.1 src/tools/compat/configure \ src/tools/compat/configure.ac cvs rdiff -u -r1.53 -r1.53.6.1 src/tools/compat/nbtool_config.h.in Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.c diff -u src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.c:1.5 src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.c:1.5.10.1 --- src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.c:1.5 Thu Jun 20 14:33:04 2019 +++ src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.c Fri Jun 30 17:13:50 2023 @@ -42,6 +42,7 @@ * get a return code of 0. */ +#include <errno.h> #include <pthread.h> #ifdef illumos #include <synch.h> @@ -49,15 +50,22 @@ #include <stdio.h> #include "barrier.h" +#include "ctftools.h" void barrier_init(barrier_t *bar, int nthreads) { - pthread_mutex_init(&bar->bar_lock, NULL); + if ((errno = pthread_mutex_init(&bar->bar_lock, NULL)) != 0) + terminate("%s: pthread_mutex_init(bar_lock)", __func__); #ifdef illumos - sema_init(&bar->bar_sem, 0, USYNC_THREAD, NULL); + if ((errno = sema_init(&bar->bar_sem, 0, USYNC_THREAD, NULL)) != 0) + terminate("%s: sema_init(bar_sem)", __func__); +#elif defined(HAVE_DISPATCH_SEMAPHORE_CREATE) + if ((bar->bar_sem = dispatch_semaphore_create(0)) == NULL) + terminate("%s: dispatch_semaphore_create()\n", __func__); #else - sem_init(&bar->bar_sem, 0, 0); + if (sem_init(&bar->bar_sem, 0, 0) == -1) + terminate("%s: sem_init(bar_sem)", __func__); #endif bar->bar_numin = 0; @@ -67,14 +75,26 @@ barrier_init(barrier_t *bar, int nthread int barrier_wait(barrier_t *bar) { - pthread_mutex_lock(&bar->bar_lock); +#if defined(HAVE_DISPATCH_SEMAPHORE_CREATE) + long error; +#endif + if ((errno = pthread_mutex_lock(&bar->bar_lock)) != 0) + terminate("%s: pthread_mutex_lock(bar_lock)", __func__); if (++bar->bar_numin < bar->bar_nthr) { - pthread_mutex_unlock(&bar->bar_lock); + if ((errno = pthread_mutex_unlock(&bar->bar_lock)) != 0) + terminate("%s: pthread_mutex_unlock(bar_lock)", + __func__); #ifdef illumos - sema_wait(&bar->bar_sem); + if ((errno = sema_wait(&bar->bar_sem)) != 0) + terminate("%s: sema_wait(bar_sem)", __func__); +#elif defined(HAVE_DISPATCH_SEMAPHORE_CREATE) + if ((error = dispatch_semaphore_wait(bar->bar_sem, DISPATCH_TIME_FOREVER)) != 0) + terminate("%s: dispatch_semaphore_wait(bar_sem) = %ld\n", + __func__, error); #else - sem_wait(&bar->bar_sem); + if (sem_wait(&bar->bar_sem) == -1) + terminate("%s: sem_wait(bar_sem)", __func__); #endif return (0); @@ -84,13 +104,21 @@ barrier_wait(barrier_t *bar) /* reset for next use */ bar->bar_numin = 0; - for (i = 1; i < bar->bar_nthr; i++) + for (i = 1; i < bar->bar_nthr; i++) { #ifdef illumos - sema_post(&bar->bar_sem); + if ((errno = sema_post(&bar->bar_sem)) != 0) + terminate("%s: sema_post(bar_sem)", __func__); +#elif defined(HAVE_DISPATCH_SEMAPHORE_CREATE) + /* return value doesn't matter */ + dispatch_semaphore_signal(bar->bar_sem); #else - sem_post(&bar->bar_sem); + if (sem_post(&bar->bar_sem) == -1) + terminate("%s: sem_post(bar_sem)", __func__); #endif - pthread_mutex_unlock(&bar->bar_lock); + } + if ((errno = pthread_mutex_unlock(&bar->bar_lock)) != 0) + terminate("%s: pthread_mutex_unlock(bar_lock)", + __func__); return (1); } Index: src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.h diff -u src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.h:1.3 src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.h:1.3.12.1 --- src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.h:1.3 Mon May 28 21:05:06 2018 +++ src/external/cddl/osnet/dist/tools/ctf/cvt/barrier.h Fri Jun 30 17:13:50 2023 @@ -33,8 +33,15 @@ * APIs for the barrier synchronization primitive. */ +#ifdef HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #ifdef illumos #include <synch.h> +#elif defined(HAVE_DISPATCH_SEMAPHORE_CREATE) +#include <dispatch/dispatch.h> +typedef dispatch_semaphore_t sema_t; #else #include <semaphore.h> typedef sem_t sema_t; Index: src/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c diff -u src/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c:1.17 src/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c:1.17.8.1 --- src/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c:1.17 Sun Oct 13 21:32:07 2019 +++ src/external/cddl/osnet/dist/tools/ctf/cvt/ctfmerge.c Fri Jun 30 17:13:50 2023 @@ -373,22 +373,31 @@ init_phase_two(workqueue_t *wq) static void wip_save_work(workqueue_t *wq, wip_t *slot, int slotnum) { - pthread_mutex_lock(&wq->wq_donequeue_lock); - - while (wq->wq_lastdonebatch + 1 < slot->wip_batchid) - pthread_cond_wait(&slot->wip_cv, &wq->wq_donequeue_lock); + if ((errno = pthread_mutex_lock(&wq->wq_donequeue_lock)) != 0) + terminate("%s: pthread_mutex_lock(wq_donequeue_lock)", + __func__); + + while (wq->wq_lastdonebatch + 1 < slot->wip_batchid) { + if ((errno = pthread_cond_wait(&slot->wip_cv, &wq->wq_donequeue_lock)) != 0) + terminate("%s: pthread_cond_wait(wip_cv,wq_donequeue_lock)", + __func__); + } assert(wq->wq_lastdonebatch + 1 == slot->wip_batchid); fifo_add(wq->wq_donequeue, slot->wip_td); wq->wq_lastdonebatch++; - pthread_cond_signal(&wq->wq_wip[(slotnum + 1) % - wq->wq_nwipslots].wip_cv); + const int nextslot = (slotnum + 1) % wq->wq_nwipslots; + if ((errno = pthread_cond_signal(&wq->wq_wip[nextslot].wip_cv)) != 0) + terminate("%s: pthread_cond_signal(wq_wip[%d].wip_cv)", + __func__, nextslot); /* reset the slot for next use */ slot->wip_td = NULL; slot->wip_batchid = wq->wq_next_batchid++; - pthread_mutex_unlock(&wq->wq_donequeue_lock); + if ((errno = pthread_mutex_unlock(&wq->wq_donequeue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_donequeue_lock)", + __func__); } static void @@ -417,25 +426,35 @@ worker_runphase1(workqueue_t *wq) int wipslotnum, pownum; for (;;) { - pthread_mutex_lock(&wq->wq_queue_lock); + if ((errno = pthread_mutex_lock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_lock(wq_queue_lock)", + __func__); while (fifo_empty(wq->wq_queue)) { if (wq->wq_nomorefiles == 1) { - pthread_cond_broadcast(&wq->wq_work_avail); - pthread_mutex_unlock(&wq->wq_queue_lock); + if ((errno = pthread_cond_broadcast(&wq->wq_work_avail)) != 0) + terminate("%s: pthread_cond_broadcast(wq_work_avail)", + __func__); + if ((errno = pthread_mutex_unlock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", + __func__); /* on to phase 2 ... */ return; } - pthread_cond_wait(&wq->wq_work_avail, - &wq->wq_queue_lock); + if ((errno = pthread_cond_wait(&wq->wq_work_avail, + &wq->wq_queue_lock)) != 0) + terminate("%s: pthread_cond_wait(wq_work_avail,wq_queue_lock)", + __func__); } /* there's work to be done! */ pow = fifo_remove(wq->wq_queue); pownum = wq->wq_nextpownum++; - pthread_cond_broadcast(&wq->wq_work_removed); + if ((errno = pthread_cond_broadcast(&wq->wq_work_removed)) != 0) + terminate("%s: pthread_cond_broadcast(wq_work_removed)", + __func__); assert(pow != NULL); @@ -443,16 +462,21 @@ worker_runphase1(workqueue_t *wq) wipslotnum = pownum % wq->wq_nwipslots; wipslot = &wq->wq_wip[wipslotnum]; - pthread_mutex_lock(&wipslot->wip_lock); + if ((errno = pthread_mutex_lock(&wipslot->wip_lock)) != 0) + terminate("%s: pthread_mutex_lock(wip_lock)", __func__); - pthread_mutex_unlock(&wq->wq_queue_lock); + if ((errno = pthread_mutex_unlock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", + __func__); wip_add_work(wipslot, pow); if (wipslot->wip_nmerged == wq->wq_maxbatchsz) wip_save_work(wq, wipslot, wipslotnum); - pthread_mutex_unlock(&wipslot->wip_lock); + if ((errno = pthread_mutex_unlock(&wipslot->wip_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wip_lock)", + __func__); } } @@ -463,28 +487,44 @@ worker_runphase2(workqueue_t *wq) int batchid; for (;;) { - pthread_mutex_lock(&wq->wq_queue_lock); + if ((errno = pthread_mutex_lock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_lock(wq_queue_lock)", + __func__); if (wq->wq_ninqueue == 1) { - pthread_cond_broadcast(&wq->wq_work_avail); - pthread_mutex_unlock(&wq->wq_queue_lock); + if ((errno = pthread_cond_broadcast(&wq->wq_work_avail)) != 0) + terminate("%s: pthread_cond_broadcast(wq_work_avail)", + __func__); + if ((errno = pthread_mutex_unlock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", + __func__); debug(2, "0x%jx: entering p2 completion barrier\n", (uintmax_t)(uintptr_t)pthread_self()); if (barrier_wait(&wq->wq_bar1)) { - pthread_mutex_lock(&wq->wq_queue_lock); + if ((errno = pthread_mutex_lock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_lock(wq_queue_lock)", + __func__); wq->wq_alldone = 1; - pthread_cond_signal(&wq->wq_alldone_cv); - pthread_mutex_unlock(&wq->wq_queue_lock); + if ((errno = pthread_cond_signal(&wq->wq_alldone_cv)) != 0) + terminate("%s: pthread_cond_signal(wq_alldone_cv)", + __func__); + if ((errno = pthread_mutex_unlock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", + __func__); } return; } if (fifo_len(wq->wq_queue) < 2) { - pthread_cond_wait(&wq->wq_work_avail, - &wq->wq_queue_lock); - pthread_mutex_unlock(&wq->wq_queue_lock); + if ((errno = pthread_cond_wait(&wq->wq_work_avail, + &wq->wq_queue_lock)) != 0) + terminate("%s: pthread_cond_wait(wq_work_avail,wq_queue_lock)", + __func__); + if ((errno = pthread_mutex_unlock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", + __func__); continue; } @@ -495,7 +535,9 @@ worker_runphase2(workqueue_t *wq) batchid = wq->wq_next_batchid++; - pthread_mutex_unlock(&wq->wq_queue_lock); + if ((errno = pthread_mutex_unlock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", + __func__); debug(2, "0x%jx: merging %p into %p\n", (uintmax_t)(uintptr_t)pthread_self(), @@ -507,10 +549,14 @@ worker_runphase2(workqueue_t *wq) * merging is complete. place at the tail of the queue in * proper order. */ - pthread_mutex_lock(&wq->wq_queue_lock); + if ((errno = pthread_mutex_lock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_lock(wq_queue_lock)", + __func__); while (wq->wq_lastdonebatch + 1 != batchid) { - pthread_cond_wait(&wq->wq_done_cv, - &wq->wq_queue_lock); + if ((errno = pthread_cond_wait(&wq->wq_done_cv, + &wq->wq_queue_lock)) != 0) + terminate("%s: pthread_cond_wait(wq_done_cv,wq_queue_lock)", + __func__); } wq->wq_lastdonebatch = batchid; @@ -519,9 +565,15 @@ worker_runphase2(workqueue_t *wq) debug(2, "0x%jx: added %p to queue, len now %d, ninqueue %d\n", (uintmax_t)(uintptr_t)pthread_self(), (void *)pow2, fifo_len(wq->wq_queue), wq->wq_ninqueue); - pthread_cond_broadcast(&wq->wq_done_cv); - pthread_cond_signal(&wq->wq_work_avail); - pthread_mutex_unlock(&wq->wq_queue_lock); + if ((errno = pthread_cond_broadcast(&wq->wq_done_cv)) != 0) + terminate("%s: pthread_cond_broadcast(wq_done_cv)", + __func__); + if ((errno = pthread_cond_signal(&wq->wq_work_avail)) != 0) + terminate("%s: pthread_cond_signal(wq_work_avail)", + __func__); + if ((errno = pthread_mutex_unlock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", + __func__); } } @@ -574,18 +626,23 @@ merge_ctf_cb(tdata_t *td, char *name, vo debug(3, "Adding tdata %p for processing\n", (void *)td); - pthread_mutex_lock(&wq->wq_queue_lock); + if ((errno = pthread_mutex_lock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_lock(wq_queue_lock)", __func__); while (fifo_len(wq->wq_queue) > wq->wq_ithrottle) { debug(2, "Throttling input (len = %d, throttle = %d)\n", fifo_len(wq->wq_queue), wq->wq_ithrottle); - pthread_cond_wait(&wq->wq_work_removed, &wq->wq_queue_lock); + if ((errno = pthread_cond_wait(&wq->wq_work_removed, &wq->wq_queue_lock)) != 0) + terminate("%s: pthread_cond_wait(wq_work_removed,wq_queue_lock)", + __func__); } fifo_add(wq->wq_queue, td); debug(1, "Thread 0x%jx announcing %s\n", (uintmax_t)(uintptr_t)pthread_self(), name); - pthread_cond_broadcast(&wq->wq_work_avail); - pthread_mutex_unlock(&wq->wq_queue_lock); + if ((errno = pthread_cond_broadcast(&wq->wq_work_avail)) != 0) + terminate("%s: pthread_cond_broadcast(wq_work_avail)", __func__); + if ((errno = pthread_mutex_unlock(&wq->wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", __func__); return (1); } @@ -690,25 +747,35 @@ wq_init(workqueue_t *wq, int nfiles) wq->wq_next_batchid = 0; for (i = 0; i < nslots; i++) { - pthread_mutex_init(&wq->wq_wip[i].wip_lock, NULL); - pthread_cond_init(&wq->wq_wip[i].wip_cv, NULL); + if ((errno = pthread_mutex_init(&wq->wq_wip[i].wip_lock, NULL)) != 0) + terminate("%s: pthread_mutex_init(wip[%d].wip_lock", + __func__, i); + if ((errno = pthread_cond_init(&wq->wq_wip[i].wip_cv, NULL)) != 0) + terminate("%s: pthread_cond_init(wip[%d].wip_cv", + __func__, i); wq->wq_wip[i].wip_batchid = wq->wq_next_batchid++; } - pthread_mutex_init(&wq->wq_queue_lock, NULL); + if ((errno = pthread_mutex_init(&wq->wq_queue_lock, NULL)) != 0) + terminate("%s: pthread_mutex_init(wq_queue_lock)", __func__); wq->wq_queue = fifo_new(); - pthread_cond_init(&wq->wq_work_avail, NULL); - pthread_cond_init(&wq->wq_work_removed, NULL); + if ((errno = pthread_cond_init(&wq->wq_work_avail, NULL)) != 0) + terminate("%s: pthread_cond_init(wq_work_avail)", __func__); + if ((errno = pthread_cond_init(&wq->wq_work_removed, NULL)) != 0) + terminate("%s: pthread_cond_init(wq_work_removed", __func__); wq->wq_ninqueue = nfiles; wq->wq_nextpownum = 0; - pthread_mutex_init(&wq->wq_donequeue_lock, NULL); + if ((errno = pthread_mutex_init(&wq->wq_donequeue_lock, NULL)) != 0) + terminate("%s: pthread_mutex_init(wq_donequeue_lock)", __func__); wq->wq_donequeue = fifo_new(); wq->wq_lastdonebatch = -1; - pthread_cond_init(&wq->wq_done_cv, NULL); + if ((errno = pthread_cond_init(&wq->wq_done_cv, NULL)) != 0) + terminate("%s: pthread_cond_init(wq_done_cv)", __func__); - pthread_cond_init(&wq->wq_alldone_cv, NULL); + if ((errno = pthread_cond_init(&wq->wq_alldone_cv, NULL)) != 0) + terminate("%s: pthread_cond_init(wq_alldone_cv)", __func__); wq->wq_alldone = 0; barrier_init(&wq->wq_bar1, wq->wq_nthreads); @@ -727,10 +794,13 @@ start_threads(workqueue_t *wq) sigaddset(&sets, SIGINT); sigaddset(&sets, SIGQUIT); sigaddset(&sets, SIGTERM); - pthread_sigmask(SIG_BLOCK, &sets, NULL); + if ((errno = pthread_sigmask(SIG_BLOCK, &sets, NULL)) != 0) + terminate("%s: pthread_sigmask(SIG_BLOCK)", __func__); for (i = 0; i < wq->wq_nthreads; i++) { - pthread_create(&wq->wq_thread[i], NULL, worker_thread, wq); + if ((errno = pthread_create(&wq->wq_thread[i], NULL, worker_thread, wq)) != 0) + terminate("%s: pthread_create(wq_thread[%d]", + __func__, i); } #ifdef illumos @@ -742,7 +812,8 @@ start_threads(workqueue_t *wq) signal(SIGQUIT, handle_sig); signal(SIGTERM, handle_sig); #endif - pthread_sigmask(SIG_UNBLOCK, &sets, NULL); + if ((errno = pthread_sigmask(SIG_UNBLOCK, &sets, NULL)) != 0) + terminate("%s: pthread_sigmask(SIG_UNBLOCK)", __func__); } static void @@ -751,7 +822,9 @@ join_threads(workqueue_t *wq) int i; for (i = 0; i < wq->wq_nthreads; i++) { - pthread_join(wq->wq_thread[i], NULL); + if ((errno = pthread_join(wq->wq_thread[i], NULL)) != 0) + terminate("%s: pthread_join(wq_thread[%d]", + __func__, i); } } @@ -947,15 +1020,23 @@ main(int argc, char **argv) terminate("No ctf sections found to merge\n"); } - pthread_mutex_lock(&wq.wq_queue_lock); + if ((errno = pthread_mutex_lock(&wq.wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_lock(wq_queue_lock)", __func__); wq.wq_nomorefiles = 1; - pthread_cond_broadcast(&wq.wq_work_avail); - pthread_mutex_unlock(&wq.wq_queue_lock); - - pthread_mutex_lock(&wq.wq_queue_lock); - while (wq.wq_alldone == 0) - pthread_cond_wait(&wq.wq_alldone_cv, &wq.wq_queue_lock); - pthread_mutex_unlock(&wq.wq_queue_lock); + if ((errno = pthread_cond_broadcast(&wq.wq_work_avail)) != 0) + terminate("%s: pthread_cond_broadcast(wq_work_avail)", __func__); + if ((errno = pthread_mutex_unlock(&wq.wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", __func__); + + if ((errno = pthread_mutex_lock(&wq.wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_lock(wq_queue_lock)", __func__); + while (wq.wq_alldone == 0) { + if ((errno = pthread_cond_wait(&wq.wq_alldone_cv, &wq.wq_queue_lock)) != 0) + terminate("%s: pthread_cond_wait(wq_alldone_cv,wq_queue_lock)", + __func__); + } + if ((errno = pthread_mutex_unlock(&wq.wq_queue_lock)) != 0) + terminate("%s: pthread_mutex_unlock(wq_queue_lock)", __func__); join_threads(&wq); Index: src/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c diff -u src/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c:1.9 src/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c:1.9.12.1 --- src/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c:1.9 Mon May 28 21:05:06 2018 +++ src/external/cddl/osnet/dist/tools/ctf/cvt/tdata.c Fri Jun 30 17:13:50 2023 @@ -31,6 +31,7 @@ # include "nbtool_config.h" #endif +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <strings.h> @@ -396,7 +397,8 @@ tdata_new(void) new->td_nextid = 1; new->td_curvgen = 1; - pthread_mutex_init(&new->td_mergelock, NULL); + if ((errno = pthread_mutex_init(&new->td_mergelock, NULL)) != 0) + terminate("%s: pthread_mutex_init(td_mergelock)", __func__); return (new); } @@ -414,7 +416,8 @@ tdata_free(tdata_t *td) free(td->td_parlabel); free(td->td_parname); - pthread_mutex_destroy(&td->td_mergelock); + if ((errno = pthread_mutex_destroy(&td->td_mergelock)) != 0) + terminate("%s: pthread_mutex_destroy(td_mergelock)", __func__); free(td); } Index: src/external/cddl/osnet/sys/sys/opentypes.h diff -u src/external/cddl/osnet/sys/sys/opentypes.h:1.6 src/external/cddl/osnet/sys/sys/opentypes.h:1.6.6.1 --- src/external/cddl/osnet/sys/sys/opentypes.h:1.6 Thu Apr 15 07:00:50 2021 +++ src/external/cddl/osnet/sys/sys/opentypes.h Fri Jun 30 17:13:50 2023 @@ -37,8 +37,12 @@ typedef id_t ctid_t; #define B_FALSE 0 #define B_TRUE 1 #ifndef _KERNEL +#if defined(__APPLE__) +#include <mach/boolean.h> +#else typedef int boolean_t; #endif +#endif #ifndef __defined_hr_t #define __defined_hr_t Index: src/tools/compat/configure diff -u src/tools/compat/configure:1.99 src/tools/compat/configure:1.99.6.1 --- src/tools/compat/configure:1.99 Thu Feb 25 13:41:58 2021 +++ src/tools/compat/configure Fri Jun 30 17:13:50 2023 @@ -5294,6 +5294,7 @@ _ACEOF fi for ac_func in atoll asprintf asnprintf basename devname dirfd dirname \ + dispatch_semaphore_create \ dprintf esetfunc fgetln flock fpurge __fpurge futimes getline \ getopt getopt_long group_from_gid gid_from_group \ heapsort isblank issetugid lchflags lchmod lchown lutimes mkstemp \ Index: src/tools/compat/configure.ac diff -u src/tools/compat/configure.ac:1.99 src/tools/compat/configure.ac:1.99.6.1 --- src/tools/compat/configure.ac:1.99 Thu Feb 25 13:41:58 2021 +++ src/tools/compat/configure.ac Fri Jun 30 17:13:50 2023 @@ -1,10 +1,10 @@ -# $NetBSD: configure.ac,v 1.99 2021/02/25 13:41:58 christos Exp $ +# $NetBSD: configure.ac,v 1.99.6.1 2023/06/30 17:13:50 martin Exp $ # # Autoconf definition file for libnbcompat. # # When you edit configure.ac: # 0. Create the tools versions of autoconf and autoheader: -# cd ${SRCDIR} && build.sh -V MKMAINTAINERTOOLS=yes tools +# cd ${SRCDIR} && ./build.sh -V MKMAINTAINERTOOLS=yes tools # (This might not work if you try it after editing configure.ac.) # 1. edit configure.ac # 2. Regenerate "configure" and "nbtool_config.h.in" from "configure.ac": @@ -12,7 +12,7 @@ # (Please don't use a non-tools version of autoconf or autoheader.) # 3. Test that the tools still build: # mv ${TOOLDIR} ${TOOLDIR}.bak -# cd ${SRCDIR} && build.sh -V MKMAINTAINERTOOLS=yes tools +# cd ${SRCDIR} && ./build.sh -V MKMAINTAINERTOOLS=yes tools # 4. cvs commit files that you edited. # 5. Regen again, to pick up changed RCS IDs from the above commit: # cd ${SRCDIR}/tools/compat && ${TOOLDIR}/bin/nbmake-${MACHINE} regen @@ -220,6 +220,7 @@ AC_CHECK_DECLS(sys_signame,,, [#include # Library functions (where a .h check isn't enough). AC_FUNC_ALLOCA AC_CHECK_FUNCS(atoll asprintf asnprintf basename devname dirfd dirname \ + dispatch_semaphore_create \ dprintf esetfunc fgetln flock fpurge __fpurge futimes getline \ getopt getopt_long group_from_gid gid_from_group \ heapsort isblank issetugid lchflags lchmod lchown lutimes mkstemp \ @@ -313,7 +314,7 @@ main(void) [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no) AC_DEFINE(BROKEN_FPARSELN, 1, - [Define to 1 if your `fparseln' function is broken.])], + [Define to 1 if your 'fparseln' function is broken.])], [AC_MSG_WARN([cross compiling: not checking farseln])] ) ]) Index: src/tools/compat/nbtool_config.h.in diff -u src/tools/compat/nbtool_config.h.in:1.53 src/tools/compat/nbtool_config.h.in:1.53.6.1 --- src/tools/compat/nbtool_config.h.in:1.53 Thu Feb 25 13:41:58 2021 +++ src/tools/compat/nbtool_config.h.in Fri Jun 30 17:13:50 2023 @@ -1,6 +1,6 @@ /* nbtool_config.h.in. Generated from configure.ac by autoheader. */ -/* $NetBSD: nbtool_config.h.in,v 1.53 2021/02/25 13:41:58 christos Exp $ */ +/* $NetBSD: nbtool_config.h.in,v 1.53.6.1 2023/06/30 17:13:50 martin Exp $ */ #ifndef __NETBSD_NBTOOL_CONFIG_H__ #define __NETBSD_NBTOOL_CONFIG_H__ @@ -8,7 +8,7 @@ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD -/* Define to 1 if your `fparseln' function is broken. */ +/* Define to 1 if your 'fparseln' function is broken. */ #undef BROKEN_FPARSELN /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP @@ -437,6 +437,9 @@ /* Define to 1 if `__dd_fd' is a member of `DIR'. */ #undef HAVE_DIR___DD_FD +/* Define to 1 if you have the `dispatch_semaphore_create' function. */ +#undef HAVE_DISPATCH_SEMAPHORE_CREATE + /* Define to 1 if you have the `dprintf' function. */ #undef HAVE_DPRINTF