summaryrefslogtreecommitdiff
path: root/usr/src/tools/ctf/cvt/ctfmerge.c
diff options
context:
space:
mode:
authorsommerfe <none@none>2008-06-22 09:13:44 -0700
committersommerfe <none@none>2008-06-22 09:13:44 -0700
commit8168dffc63ebd561e52b272b41986e0bf88a9cca (patch)
tree4f551917e17fba3ce44c1124d5954d0cf3a8499b /usr/src/tools/ctf/cvt/ctfmerge.c
parent6e168b7fd0e87ddf9344458382d5fd574deac5e6 (diff)
downloadillumos-joyent-8168dffc63ebd561e52b272b41986e0bf88a9cca.tar.gz
6716983 left-for-dead ctfmerge worker threads awake to take out maker
Diffstat (limited to 'usr/src/tools/ctf/cvt/ctfmerge.c')
-rw-r--r--usr/src/tools/ctf/cvt/ctfmerge.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/usr/src/tools/ctf/cvt/ctfmerge.c b/usr/src/tools/ctf/cvt/ctfmerge.c
index 2def4904a6..2d00a566be 100644
--- a/usr/src/tools/ctf/cvt/ctfmerge.c
+++ b/usr/src/tools/ctf/cvt/ctfmerge.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -640,6 +640,7 @@ wq_init(workqueue_t *wq, int nfiles)
wq->wq_wip = xcalloc(sizeof (wip_t) * nslots);
wq->wq_nwipslots = nslots;
wq->wq_nthreads = MIN(sysconf(_SC_NPROCESSORS_ONLN) * 3 / 2, nslots);
+ wq->wq_thread = xmalloc(sizeof (pthread_t) * wq->wq_nthreads);
if (getenv("CTFMERGE_INPUT_THROTTLE"))
throttle = atoi(getenv("CTFMERGE_INPUT_THROTTLE"));
@@ -682,7 +683,6 @@ wq_init(workqueue_t *wq, int nfiles)
static void
start_threads(workqueue_t *wq)
{
- pthread_t thrid;
sigset_t sets;
int i;
@@ -693,8 +693,8 @@ start_threads(workqueue_t *wq)
pthread_sigmask(SIG_BLOCK, &sets, NULL);
for (i = 0; i < wq->wq_nthreads; i++) {
- pthread_create(&thrid, NULL, (void *(*)(void *))worker_thread,
- wq);
+ pthread_create(&wq->wq_thread[i], NULL,
+ (void *(*)(void *))worker_thread, wq);
}
sigset(SIGINT, handle_sig);
@@ -703,6 +703,16 @@ start_threads(workqueue_t *wq)
pthread_sigmask(SIG_UNBLOCK, &sets, NULL);
}
+static void
+join_threads(workqueue_t *wq)
+{
+ int i;
+
+ for (i = 0; i < wq->wq_nthreads; i++) {
+ pthread_join(wq->wq_thread[i], NULL);
+ }
+}
+
static int
strcompare(const void *p1, const void *p2)
{
@@ -712,10 +722,18 @@ strcompare(const void *p1, const void *p2)
return (strcmp(s1, s2));
}
+/*
+ * Core work queue structure; passed to worker threads on thread creation
+ * as the main point of coordination. Allocate as a static structure; we
+ * could have put this into a local variable in main, but passing a pointer
+ * into your stack to another thread is fragile at best and leads to some
+ * hard-to-debug failure modes.
+ */
+static workqueue_t wq;
+
int
main(int argc, char **argv)
{
- workqueue_t wq;
tdata_t *mstrtd, *savetd;
char *uniqfile = NULL, *uniqlabel = NULL;
char *withfile = NULL;
@@ -897,6 +915,8 @@ main(int argc, char **argv)
pthread_cond_wait(&wq.wq_alldone_cv, &wq.wq_queue_lock);
pthread_mutex_unlock(&wq.wq_queue_lock);
+ join_threads(&wq);
+
/*
* All requested files have been merged, with the resulting tree in
* mstrtd. savetd is the tree that will be placed into the output file.