mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 03:55:49 +00:00
Remove WorkThread::Result.
WorkThread::StartThread is now a more typical main function.
This commit is contained in:
parent
8468ef09c3
commit
7939aec743
@ -187,9 +187,9 @@ void RunQueryDbThread(const std::string& bin_name,
|
||||
SetCurrentThreadName("querydb");
|
||||
while (true) {
|
||||
bool did_work = QueryDbMainLoop(
|
||||
config, &db, waiter, &project, &file_consumer_shared,
|
||||
&import_manager, ×tamp_manager, &semantic_cache, &working_files,
|
||||
&clang_complete, &include_complete, global_code_complete_cache.get(),
|
||||
config, &db, waiter, &project, &file_consumer_shared, &import_manager,
|
||||
×tamp_manager, &semantic_cache, &working_files, &clang_complete,
|
||||
&include_complete, global_code_complete_cache.get(),
|
||||
non_global_code_complete_cache.get(), signature_cache.get());
|
||||
|
||||
// Cleanup and free any unused memory.
|
||||
@ -234,13 +234,14 @@ void LaunchStdinLoop(Config* config,
|
||||
|
||||
WorkThread::StartThread("stdin", [request_times]() {
|
||||
auto* queue = QueueManager::instance();
|
||||
while (true) {
|
||||
std::unique_ptr<BaseIpcMessage> message =
|
||||
MessageRegistry::instance()->ReadMessageFromStdin(
|
||||
g_log_stdin_stdout_to_stderr);
|
||||
|
||||
// Message parsing can fail if we don't recognize the method.
|
||||
if (!message)
|
||||
return WorkThread::Result::MoreWork;
|
||||
continue;
|
||||
|
||||
// Cache |method_id| so we can access it after moving |message|.
|
||||
IpcId method_id = message->method_id;
|
||||
@ -292,8 +293,7 @@ void LaunchStdinLoop(Config* config,
|
||||
}
|
||||
|
||||
default: {
|
||||
LOG_S(ERROR) << "Unhandled IPC message "
|
||||
<< IpcIdToString(method_id);
|
||||
LOG_S(ERROR) << "Unhandled IPC message " << IpcIdToString(method_id);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@ -301,9 +301,8 @@ void LaunchStdinLoop(Config* config,
|
||||
// If the message was to exit then querydb will take care of the actual
|
||||
// exit. Stop reading from stdin since it might be detached.
|
||||
if (method_id == IpcId::Exit)
|
||||
return WorkThread::Result::ExitThread;
|
||||
|
||||
return WorkThread::Result::MoreWork;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -312,11 +311,11 @@ void LaunchStdoutThread(std::unordered_map<IpcId, Timer>* request_times,
|
||||
WorkThread::StartThread("stdout", [=]() {
|
||||
auto* queue = QueueManager::instance();
|
||||
|
||||
while (true) {
|
||||
std::vector<Stdout_Request> messages = queue->for_stdout.DequeueAll();
|
||||
if (messages.empty()) {
|
||||
waiter->Wait({&queue->for_stdout});
|
||||
return queue->HasWork() ? WorkThread::Result::MoreWork
|
||||
: WorkThread::Result::NoWork;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto& message : messages) {
|
||||
@ -338,8 +337,7 @@ void LaunchStdoutThread(std::unordered_map<IpcId, Timer>* request_times,
|
||||
std::cout << message.content;
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
return WorkThread::Result::MoreWork;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ bool QueryDb_ImportMain(Config* config,
|
||||
SemanticHighlightSymbolCache* semantic_cache,
|
||||
WorkingFiles* working_files);
|
||||
|
||||
WorkThread::Result IndexMain(Config* config,
|
||||
void IndexMain(Config* config,
|
||||
FileConsumer::SharedState* file_consumer_shared,
|
||||
TimestampManager* timestamp_manager,
|
||||
ImportManager* import_manager,
|
||||
|
@ -434,7 +434,7 @@ bool IndexMergeIndexUpdates() {
|
||||
}
|
||||
}
|
||||
|
||||
WorkThread::Result IndexMain(Config* config,
|
||||
void IndexMain(Config* config,
|
||||
FileConsumer::SharedState* file_consumer_shared,
|
||||
TimestampManager* timestamp_manager,
|
||||
ImportManager* import_manager,
|
||||
@ -442,13 +442,14 @@ WorkThread::Result IndexMain(Config* config,
|
||||
Project* project,
|
||||
WorkingFiles* working_files,
|
||||
MultiQueueWaiter* waiter) {
|
||||
// Build one index per-indexer, as building the index acquires a global lock.
|
||||
ClangIndex index;
|
||||
|
||||
while (true) {
|
||||
status->num_active_threads++;
|
||||
|
||||
EmitProgress(config);
|
||||
|
||||
// Build one index per-indexer, as building the index acquires a global lock.
|
||||
ClangIndex index;
|
||||
|
||||
// TODO: process all off IndexMain_DoIndex before calling
|
||||
// IndexMain_DoCreateIndexUpdate for better icache behavior. We need to have
|
||||
// some threads spinning on both though otherwise memory usage will get bad.
|
||||
@ -481,9 +482,7 @@ WorkThread::Result IndexMain(Config* config,
|
||||
waiter->Wait({&queue->index_request, &queue->on_id_mapped,
|
||||
&queue->load_previous_index, &queue->on_indexed});
|
||||
}
|
||||
|
||||
return queue->HasWork() ? WorkThread::Result::MoreWork
|
||||
: WorkThread::Result::NoWork;
|
||||
}
|
||||
}
|
||||
|
||||
bool QueryDb_ImportMain(Config* config,
|
||||
|
@ -136,8 +136,6 @@ void IncludeComplete::Rescan() {
|
||||
|
||||
timer.ResetAndPrint("[perf] Scanning for includes");
|
||||
is_scanning = false;
|
||||
|
||||
return WorkThread::Result::ExitThread;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -4,17 +4,14 @@
|
||||
#include <loguru.hpp>
|
||||
|
||||
namespace {
|
||||
struct Ipc_CqueryWait
|
||||
: public IpcMessage<Ipc_CqueryWait> {
|
||||
struct Ipc_CqueryWait : public IpcMessage<Ipc_CqueryWait> {
|
||||
static constexpr IpcId kIpcId = IpcId::CqueryWait;
|
||||
};
|
||||
MAKE_REFLECT_EMPTY_STRUCT(Ipc_CqueryWait);
|
||||
REGISTER_IPC_MESSAGE(Ipc_CqueryWait);
|
||||
|
||||
struct CqueryWaitHandler : MessageHandler {
|
||||
IpcId GetId() const override {
|
||||
return IpcId::CqueryWait;
|
||||
}
|
||||
IpcId GetId() const override { return IpcId::CqueryWait; }
|
||||
void Run(std::unique_ptr<BaseIpcMessage> request) override {
|
||||
// TODO: use status message system here, then run querydb as normal? Maybe
|
||||
// this cannot be a normal message, ie, it needs to be re-entrant.
|
||||
|
@ -173,7 +173,7 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
|
||||
LOG_S(INFO) << "Starting " << config->indexerCount << " indexers";
|
||||
for (int i = 0; i < config->indexerCount; ++i) {
|
||||
WorkThread::StartThread("indexer" + std::to_string(i), [=]() {
|
||||
return IndexMain(config, file_consumer_shared, timestamp_manager,
|
||||
IndexMain(config, file_consumer_shared, timestamp_manager,
|
||||
import_manager, import_pipeline_status, project,
|
||||
working_files, waiter);
|
||||
});
|
||||
|
@ -4,15 +4,9 @@
|
||||
|
||||
// static
|
||||
void WorkThread::StartThread(const std::string& thread_name,
|
||||
const std::function<Result()>& entry_point) {
|
||||
std::function<void()> entry_point) {
|
||||
new std::thread([thread_name, entry_point]() {
|
||||
SetCurrentThreadName(thread_name);
|
||||
|
||||
// Main loop.
|
||||
while (true) {
|
||||
Result result = entry_point();
|
||||
if (result == Result::ExitThread)
|
||||
break;
|
||||
}
|
||||
entry_point();
|
||||
});
|
||||
}
|
@ -9,13 +9,10 @@
|
||||
// Helper methods for starting threads that do some work. Enables test code to
|
||||
// wait for all work to complete.
|
||||
struct WorkThread {
|
||||
// FIXME: remove result, have entry_point run a while(true) loop.
|
||||
enum class Result { MoreWork, NoWork, ExitThread };
|
||||
|
||||
// Launch a new thread. |entry_point| will be called continously. It should
|
||||
// return true if it there is still known work to be done.
|
||||
static void StartThread(const std::string& thread_name,
|
||||
const std::function<Result()>& entry_point);
|
||||
std::function<void()> entry_point);
|
||||
|
||||
// Static-only class.
|
||||
WorkThread() = delete;
|
||||
|
Loading…
Reference in New Issue
Block a user