summaryrefslogtreecommitdiffstats
path: root/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c
diff options
context:
space:
mode:
authorrpaulo <rpaulo@FreeBSD.org>2010-08-02 13:40:53 +0000
committerrpaulo <rpaulo@FreeBSD.org>2010-08-02 13:40:53 +0000
commit577761e1812fe4592e28db32d4518e8cba986503 (patch)
tree3fd229f631527cecfed36a148a8b8d4077b143b5 /cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c
parent796dcddd184bb641110681caa8686cd769bc02ac (diff)
parent679969c11d8f283ad56fa4b5bbd853cd1e7aa8fa (diff)
downloadFreeBSD-src-577761e1812fe4592e28db32d4518e8cba986503.zip
FreeBSD-src-577761e1812fe4592e28db32d4518e8cba986503.tar.gz
MFV OpenSolaris DTrace userland bits.
Diffstat (limited to 'cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c')
-rw-r--r--cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c b/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c
index 546dcdf..fa4fbeb 100644
--- a/cddl/contrib/opensolaris/tools/ctf/cvt/ctfmerge.c
+++ b/cddl/contrib/opensolaris/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.
*/
@@ -650,6 +650,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"));
@@ -692,7 +693,6 @@ wq_init(workqueue_t *wq, int nfiles)
static void
start_threads(workqueue_t *wq)
{
- pthread_t thrid;
sigset_t sets;
int i;
@@ -703,8 +703,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);
}
#if defined(sun)
@@ -719,6 +719,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)
{
@@ -728,10 +738,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;
@@ -913,6 +931,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.
OpenPOWER on IntegriCloud