diff --git a/src/xrt/auxiliary/util/u_worker.c b/src/xrt/auxiliary/util/u_worker.c index 562a3d8be..7f191a311 100644 --- a/src/xrt/auxiliary/util/u_worker.c +++ b/src/xrt/auxiliary/util/u_worker.c @@ -40,6 +40,9 @@ struct thread // Native thread. struct os_thread thread; + + //! Thread name. + char name[64]; }; struct pool @@ -78,6 +81,9 @@ struct pool //! Is the pool up and running? bool running; + + //! Prefix to use for thread names. + char prefix[32]; }; struct group @@ -335,6 +341,9 @@ run_func(void *ptr) struct thread *t = (struct thread *)ptr; struct pool *p = t->p; + snprintf(t->name, sizeof(t->name), "%s: Worker", p->prefix); + U_TRACE_SET_THREAD_NAME(t->name); + os_mutex_lock(&p->mutex); while (p->running) { @@ -387,7 +396,7 @@ run_func(void *ptr) */ struct u_worker_thread_pool * -u_worker_thread_pool_create(uint32_t starting_worker_count, uint32_t thread_count) +u_worker_thread_pool_create(uint32_t starting_worker_count, uint32_t thread_count, const char *prefix) { XRT_TRACE_MARKER(); int ret; @@ -408,6 +417,7 @@ u_worker_thread_pool_create(uint32_t starting_worker_count, uint32_t thread_coun p->worker_limit = starting_worker_count; p->thread_count = thread_count; p->running = true; + snprintf(p->prefix, sizeof(p->prefix), "%s", prefix); ret = os_mutex_init(&p->mutex); if (ret != 0) { diff --git a/src/xrt/auxiliary/util/u_worker.h b/src/xrt/auxiliary/util/u_worker.h index 4468b2f31..e36c340da 100644 --- a/src/xrt/auxiliary/util/u_worker.h +++ b/src/xrt/auxiliary/util/u_worker.h @@ -42,11 +42,13 @@ struct u_worker_thread_pool * @param thread_count The number of threads to be created in total, * this is the maximum threads that can be in * flight at the same time. + * @param prefix Prefix to used when naming threads, used for + * tracing and debugging. * * @ingroup aux_util */ struct u_worker_thread_pool * -u_worker_thread_pool_create(uint32_t starting_worker_count, uint32_t thread_count); +u_worker_thread_pool_create(uint32_t starting_worker_count, uint32_t thread_count, const char *prefix); /*! * Internal function, only called by reference. diff --git a/src/xrt/auxiliary/util/u_worker.hpp b/src/xrt/auxiliary/util/u_worker.hpp index a2e8a4de6..7f204005a 100644 --- a/src/xrt/auxiliary/util/u_worker.hpp +++ b/src/xrt/auxiliary/util/u_worker.hpp @@ -51,9 +51,9 @@ public: /*! * @copydoc u_worker_thread_pool_create */ - SharedThreadPool(uint32_t starting_worker_count, uint32_t thread_count) + SharedThreadPool(uint32_t starting_worker_count, uint32_t thread_count, const char *prefix) { - mPool = u_worker_thread_pool_create(starting_worker_count, thread_count); + mPool = u_worker_thread_pool_create(starting_worker_count, thread_count, prefix); } ~SharedThreadPool() diff --git a/src/xrt/tracking/hand/mercury/hg_sync.cpp b/src/xrt/tracking/hand/mercury/hg_sync.cpp index 1dad9de59..e78d67488 100644 --- a/src/xrt/tracking/hand/mercury/hg_sync.cpp +++ b/src/xrt/tracking/hand/mercury/hg_sync.cpp @@ -1047,7 +1047,7 @@ t_hand_tracking_sync_mercury_create(struct t_stereo_camera_calibration *calib, hgt->views[1].view = 1; int num_threads = 4; - hgt->pool = u_worker_thread_pool_create(num_threads - 1, num_threads); + hgt->pool = u_worker_thread_pool_create(num_threads - 1, num_threads, "Hand Tracking"); hgt->group = u_worker_group_create(hgt->pool); lm::optimizer_create(hgt->left_in_right, false, hgt->log_level, &hgt->kinematic_hands[0]); diff --git a/tests/tests_worker.cpp b/tests/tests_worker.cpp index 735700d74..be03398e3 100644 --- a/tests/tests_worker.cpp +++ b/tests/tests_worker.cpp @@ -20,7 +20,7 @@ using namespace xrt::auxiliary::util; TEST_CASE("TaskCollection") { - SharedThreadPool pool{2, 3}; + SharedThreadPool pool{2, 3, "Test"}; bool calledA[] = { false, false,