ccls/src/messages/cquery_wait.cc

45 lines
1.4 KiB
C++
Raw Normal View History

2017-12-29 16:29:47 +00:00
#include "import_manager.h"
#include "import_pipeline.h"
2017-12-06 03:32:33 +00:00
#include "message_handler.h"
2017-12-29 16:29:47 +00:00
#include "queue_manager.h"
2017-12-06 03:32:33 +00:00
#include <loguru.hpp>
namespace {
struct Ipc_CqueryWait : public NotificationMessage<Ipc_CqueryWait> {
2017-12-28 16:55:46 +00:00
static constexpr IpcId kIpcId = IpcId::CqueryWait;
2017-12-06 04:39:44 +00:00
};
2017-12-28 16:55:46 +00:00
MAKE_REFLECT_EMPTY_STRUCT(Ipc_CqueryWait);
REGISTER_IPC_MESSAGE(Ipc_CqueryWait);
2017-12-06 04:39:44 +00:00
2017-12-28 16:55:46 +00:00
struct CqueryWaitHandler : MessageHandler {
IpcId GetId() const override { return IpcId::CqueryWait; }
2017-12-06 03:32:33 +00:00
void Run(std::unique_ptr<BaseIpcMessage> request) override {
2017-12-28 16:55:46 +00:00
// 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.
2017-12-06 03:32:33 +00:00
LOG_S(INFO) << "Waiting for idle";
int idle_count = 0;
while (true) {
bool has_work = false;
2017-12-28 16:55:46 +00:00
has_work |= import_pipeline_status->num_active_threads != 0;
2017-12-24 00:25:18 +00:00
has_work |= QueueManager::instance()->HasWork();
has_work |=
QueryDb_ImportMain(config, db, import_manager, import_pipeline_status,
semantic_cache, working_files);
2017-12-06 03:32:33 +00:00
if (!has_work)
++idle_count;
else
idle_count = 0;
// There are race conditions between each of the three checks above,
// so we retry a bunch of times to try to avoid any.
if (idle_count > 10)
break;
}
LOG_S(INFO) << "Done waiting for idle";
}
};
2017-12-28 16:55:46 +00:00
REGISTER_MESSAGE_HANDLER(CqueryWaitHandler);
} // namespace