From ea4c14c3aa79faf2734c2ab09ca871216926c232 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Fri, 20 May 2022 11:06:27 -0500 Subject: [PATCH] a/os: Rename os_thread_helper_stop to os_thread_helper_stop_and_wait --- src/xrt/auxiliary/os/os_threading.h | 6 +++--- src/xrt/auxiliary/tracking/t_tracker_psmv.cpp | 2 +- src/xrt/auxiliary/tracking/t_tracker_psvr.cpp | 2 +- src/xrt/auxiliary/tracking/t_tracker_slam.cpp | 2 +- src/xrt/compositor/main/comp_target_swapchain.c | 2 +- src/xrt/compositor/main/comp_window_mswin.c | 5 +++-- src/xrt/drivers/euroc/euroc_player.cpp | 2 +- src/xrt/drivers/survive/survive_driver.c | 3 ++- src/xrt/drivers/ultraleap_v2/ulv2_driver.cpp | 4 +++- src/xrt/drivers/vf/vf_driver.c | 2 +- src/xrt/targets/cli/cli_cmd_slambatch.c | 3 ++- 11 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/xrt/auxiliary/os/os_threading.h b/src/xrt/auxiliary/os/os_threading.h index 910657c34..cea0fb946 100644 --- a/src/xrt/auxiliary/os/os_threading.h +++ b/src/xrt/auxiliary/os/os_threading.h @@ -483,7 +483,7 @@ os_thread_helper_signal_stop(struct os_thread_helper *oth) * @public @memberof os_thread_helper */ static inline int -os_thread_helper_stop(struct os_thread_helper *oth) +os_thread_helper_stop_and_wait(struct os_thread_helper *oth) { void *retval = NULL; @@ -515,7 +515,7 @@ os_thread_helper_stop(struct os_thread_helper *oth) /*! * Destroy the thread helper, externally synchronizable. * - * Integrates a call to @ref os_thread_helper_stop, so you may just call this for full cleanup + * Integrates a call to @ref os_thread_helper_stop_and_wait, so you may just call this for full cleanup * * @public @memberof os_thread_helper */ @@ -524,7 +524,7 @@ os_thread_helper_destroy(struct os_thread_helper *oth) { assert(oth->initialized); // Stop the thread. - os_thread_helper_stop(oth); + os_thread_helper_stop_and_wait(oth); // Destroy resources. pthread_mutex_destroy(&oth->mutex); diff --git a/src/xrt/auxiliary/tracking/t_tracker_psmv.cpp b/src/xrt/auxiliary/tracking/t_tracker_psmv.cpp index bf5d2f9b7..d9fb7a19d 100644 --- a/src/xrt/auxiliary/tracking/t_tracker_psmv.cpp +++ b/src/xrt/auxiliary/tracking/t_tracker_psmv.cpp @@ -452,7 +452,7 @@ frame(TrackerPSMV &t, struct xrt_frame *xf) static void break_apart(TrackerPSMV &t) { - os_thread_helper_stop(&t.oth); + os_thread_helper_stop_and_wait(&t.oth); } } // namespace xrt::auxiliary::tracking::psmv diff --git a/src/xrt/auxiliary/tracking/t_tracker_psvr.cpp b/src/xrt/auxiliary/tracking/t_tracker_psvr.cpp index 5fc613827..e5664b40d 100644 --- a/src/xrt/auxiliary/tracking/t_tracker_psvr.cpp +++ b/src/xrt/auxiliary/tracking/t_tracker_psvr.cpp @@ -1948,7 +1948,7 @@ frame(TrackerPSVR &t, struct xrt_frame *xf) static void break_apart(TrackerPSVR &t) { - os_thread_helper_stop(&t.oth); + os_thread_helper_stop_and_wait(&t.oth); } } // namespace xrt::auxiliary::tracking::psvr diff --git a/src/xrt/auxiliary/tracking/t_tracker_slam.cpp b/src/xrt/auxiliary/tracking/t_tracker_slam.cpp index a6ff778d6..aa2e91184 100644 --- a/src/xrt/auxiliary/tracking/t_tracker_slam.cpp +++ b/src/xrt/auxiliary/tracking/t_tracker_slam.cpp @@ -913,7 +913,7 @@ t_slam_node_break_apart(struct xrt_frame_node *node) auto &t = *container_of(node, TrackerSlam, node); t.slam->finalize(); t.slam->stop(); - os_thread_helper_stop(&t.oth); + os_thread_helper_stop_and_wait(&t.oth); SLAM_DEBUG("SLAM tracker dismantled"); } diff --git a/src/xrt/compositor/main/comp_target_swapchain.c b/src/xrt/compositor/main/comp_target_swapchain.c index 0be02247f..b1f08361f 100644 --- a/src/xrt/compositor/main/comp_target_swapchain.c +++ b/src/xrt/compositor/main/comp_target_swapchain.c @@ -937,7 +937,7 @@ comp_target_swapchain_cleanup(struct comp_target_swapchain *cts) // Thread if it has been started must be stopped first. if (cts->vblank.has_started) { - os_thread_helper_stop(&cts->vblank.event_thread); + // Destroy also stops the thread. os_thread_helper_destroy(&cts->vblank.event_thread); cts->vblank.has_started = false; } diff --git a/src/xrt/compositor/main/comp_window_mswin.c b/src/xrt/compositor/main/comp_window_mswin.c index 18051fd04..1e3423ceb 100644 --- a/src/xrt/compositor/main/comp_window_mswin.c +++ b/src/xrt/compositor/main/comp_window_mswin.c @@ -91,8 +91,9 @@ static void comp_window_mswin_destroy(struct comp_target *ct) { struct comp_window_mswin *cwm = (struct comp_window_mswin *)ct; - // Stop the Windows thread first. - os_thread_helper_stop(&cwm->oth); + + // Stop the Windows thread first, destroy also stops the thread. + os_thread_helper_destroy(&cwm->oth); comp_target_swapchain_cleanup(&cwm->base); diff --git a/src/xrt/drivers/euroc/euroc_player.cpp b/src/xrt/drivers/euroc/euroc_player.cpp index 24879d317..cb52dd25a 100644 --- a/src/xrt/drivers/euroc/euroc_player.cpp +++ b/src/xrt/drivers/euroc/euroc_player.cpp @@ -748,7 +748,7 @@ euroc_player_stream_stop(struct xrt_fs *xfs) struct euroc_player *ep = euroc_player(xfs); ep->is_running = false; - os_thread_helper_stop(&ep->play_thread); + // Destroy also stops the thread. os_thread_helper_destroy(&ep->play_thread); return true; diff --git a/src/xrt/drivers/survive/survive_driver.c b/src/xrt/drivers/survive/survive_driver.c index 20f4d7764..b7f2341be 100644 --- a/src/xrt/drivers/survive/survive_driver.c +++ b/src/xrt/drivers/survive/survive_driver.c @@ -208,7 +208,8 @@ survive_device_destroy(struct xrt_device *xdev) if (survive->sys->hmd == NULL && all_null) { U_LOG_D("Tearing down libsurvive context"); - os_thread_helper_stop(&survive->sys->event_thread); + + // Destroy also stops the thread. os_thread_helper_destroy(&survive->sys->event_thread); // Now that the thread is not running we can destroy the lock. diff --git a/src/xrt/drivers/ultraleap_v2/ulv2_driver.cpp b/src/xrt/drivers/ultraleap_v2/ulv2_driver.cpp index 8a1c24fb5..effe541b2 100644 --- a/src/xrt/drivers/ultraleap_v2/ulv2_driver.cpp +++ b/src/xrt/drivers/ultraleap_v2/ulv2_driver.cpp @@ -369,7 +369,9 @@ ulv2_device_destroy(struct xrt_device *xdev) struct ulv2_device *ulv2d = ulv2_device(xdev); ulv2d->pthread_should_stop = true; - os_thread_helper_stop(&ulv2d->leap_loop_oth); + + // Destroy also stops the thread. + os_thread_helper_destroy(&ulv2d->leap_loop_oth); // Remove the variable tracking. u_var_remove_root(ulv2d); diff --git a/src/xrt/drivers/vf/vf_driver.c b/src/xrt/drivers/vf/vf_driver.c index 7e23aff2f..cefb12bb2 100644 --- a/src/xrt/drivers/vf/vf_driver.c +++ b/src/xrt/drivers/vf/vf_driver.c @@ -401,7 +401,7 @@ vf_fs_destroy(struct vf_fs *vid) { g_main_loop_quit(vid->loop); - os_thread_helper_stop(&vid->play_thread); + // Destroy also stops the thread. os_thread_helper_destroy(&vid->play_thread); free(vid); diff --git a/src/xrt/targets/cli/cli_cmd_slambatch.c b/src/xrt/targets/cli/cli_cmd_slambatch.c index e3e60a623..0b3db4035 100644 --- a/src/xrt/targets/cli/cli_cmd_slambatch.c +++ b/src/xrt/targets/cli/cli_cmd_slambatch.c @@ -74,7 +74,8 @@ cli_cmd_slambatch(int argc, const char **argv) timepoint_ns end_time = os_monotonic_get_ns(); pthread_cancel(wfk_thread.thread); - os_thread_helper_stop(&wfk_thread); + + // Destroy also stops the thread. os_thread_helper_destroy(&wfk_thread); printf("Done in %.2fs.\n", (double)(end_time - start_time) / U_TIME_1S_IN_NS); -- 2.51.2