Browse Source

Start Sophiar in another thread to reduce blocking.

jcsyshc 1 year ago
parent
commit
c9ed0cf590
3 changed files with 11 additions and 1 deletions
  1. 3 0
      CMakeLists.txt
  2. 1 0
      src/core/object_manager.h
  3. 7 1
      src/impl/apps/remote_ar/remote_ar.cpp

+ 3 - 0
CMakeLists.txt

@@ -56,6 +56,9 @@ target_include_directories(${PROJECT_NAME} PRIVATE src)
 #target_compile_options(${PROJECT_NAME} PRIVATE -g -pg)
 #target_link_options(${PROJECT_NAME} PRIVATE -g -pg)
 
+#target_compile_options(${PROJECT_NAME} PRIVATE -fsanitize=leak)
+#target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=leak)
+
 # image process sub-module
 add_subdirectory(src/image_process/cuda_impl)
 target_link_libraries(${PROJECT_NAME} ImageProcessCuda)

+ 1 - 0
src/core/object_manager.h

@@ -36,6 +36,7 @@ public:
         if (auto ctx = switch_ctx(); ctx != nullptr) [[unlikely]] {
             using boost::asio::post;
             static_assert(std::is_copy_constructible_v<RT>);
+            // TODO: figure out why some works are not called when the main thread is blocked.
             post(*ctx, [=, rt_val = RT(val), this] { save(obj_name, rt_val); });
             return;
         }

+ 7 - 1
src/impl/apps/remote_ar/remote_ar.cpp

@@ -212,7 +212,13 @@ app_remote_ar::app_remote_ar(const create_config &_conf) {
 }
 
 void app_remote_ar::start_tracking() {
-    sophiar_conn->start_object(sophiar_start_var);
+//    sophiar_conn->start_object(sophiar_start_var);
+    // work in another thread to prevent blocking
+    auto t = std::thread([this] {
+        auto conn = sophiar::local_connection();
+        conn.start_object(sophiar_start_var);
+    });
+    t.detach();
 }
 
 app_remote_ar::~app_remote_ar() {