Skip to content

Commit

Permalink
allow single thread deployment (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Aug 1, 2023
1 parent 53ce306 commit 97af61b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option(BOOST_USE_SIGNALS2 "Boost use signals2 instead of signals" ON)
option(ENABLE_ASAN "Enable Address Sanitizer (Unix Only)" OFF)
option(INSTALL_PRIVATE_HEADERS "Install private headers (usually needed for externally built Rime plugins)" OFF)
option(ENABLE_EXTERNAL_PLUGINS "Enable loading of externally built Rime plugins (from directory set by RIME_PLUGINS_DIR variable)" OFF)
option(ENABLE_THREADING "Enable threading for deployer" ON)

set(RIME_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/rime-data" CACHE STRING "Target directory for Rime data")
set(RIME_PLUGINS_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/rime-plugins" CACHE STRING "Target directory for externally built Rime plugins")
Expand Down Expand Up @@ -97,6 +98,10 @@ endif()

find_package(Threads)

if(NOT ENABLE_THREADING)
add_definitions(-DRIME_NO_THREADING)
endif()

if(BUILD_TEST)
find_package(GTest REQUIRED)
if(GTEST_FOUND)
Expand Down
5 changes: 5 additions & 0 deletions src/rime/deployer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ bool Deployer::StartWork(bool maintenance_mode) {
if (pending_tasks_.empty()) {
return false;
}
#ifdef RIME_NO_THREADING
LOG(INFO) << "running " << pending_tasks_.size() << " tasks in main thread.";
return Run();
#else
LOG(INFO) << "starting work thread for " << pending_tasks_.size()
<< " tasks.";
work_ = std::async(std::launch::async, [this] { Run(); });
return work_.valid();
#endif
}

bool Deployer::StartMaintenance() {
Expand Down

0 comments on commit 97af61b

Please sign in to comment.