Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow single thread deployment #673

Merged
merged 1 commit into from Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
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
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