From 26b5cab268c05e39e308ae2128340cf3e4a4962e Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 15 Feb 2016 08:17:34 +0100 Subject: [PATCH] Dispatcher cleanup --- src/directories.cc | 2 +- src/dispatcher.cc | 2 +- src/dispatcher.h | 2 +- src/project.cc | 4 ++-- src/source_clang.cc | 12 ++++++------ src/terminal.cc | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/directories.cc b/src/directories.cc index 977e3f7..20c8041 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -96,7 +96,7 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) { it=last_write_times.erase(it); } if(update_paths.size()>0) { - dispatcher.add([this] { + dispatcher.push([this] { update_mutex.lock(); for(auto &path: update_paths) { if(last_write_times.count(path)>0) diff --git a/src/dispatcher.cc b/src/dispatcher.cc index 4a1d80c..bc862f2 100644 --- a/src/dispatcher.cc +++ b/src/dispatcher.cc @@ -18,7 +18,7 @@ Dispatcher::~Dispatcher() { functions_mutex.unlock(); } -void Dispatcher::add(std::function function) { +void Dispatcher::push(std::function &&function) { functions_mutex.lock(); functions.emplace_back(function); functions_mutex.unlock(); diff --git a/src/dispatcher.h b/src/dispatcher.h index 70312f1..5a326e4 100644 --- a/src/dispatcher.h +++ b/src/dispatcher.h @@ -13,7 +13,7 @@ private: public: Dispatcher(); ~Dispatcher(); - void add(std::function function); + void push(std::function &&function); void disconnect(); }; diff --git a/src/project.cc b/src/project.cc index 2bd9dcb..306fbbc 100644 --- a/src/project.cc +++ b/src/project.cc @@ -275,11 +275,11 @@ void Project::Clang::debug_start() { debugging=false; Terminal::get().async_print(run_arguments+" returned: "+std::to_string(exit_status)+'\n'); }, [this](const std::string &status) { - dispatcher.add([this, status] { + dispatcher.push([this, status] { debug_update_status(status); }); }, [this](const boost::filesystem::path &file_path, int line_nr, int line_index) { - dispatcher.add([this, file_path, line_nr, line_index] { + dispatcher.push([this, file_path, line_nr, line_index] { Project::debug_stop.first=file_path; Project::debug_stop.second.first=line_nr; Project::debug_stop.second.second=line_index; diff --git a/src/source_clang.cc b/src/source_clang.cc index 9eeeaaa..5ccd484 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -111,7 +111,7 @@ void Source::ClangViewParse::parse_initialize() { break; auto expected=ParseProcessState::STARTING; if(parse_process_state.compare_exchange_strong(expected, ParseProcessState::PREPROCESSING)) { - dispatcher.add([this] { + dispatcher.push([this] { auto expected=ParseProcessState::PREPROCESSING; if(parse_mutex.try_lock()) { if(parse_process_state.compare_exchange_strong(expected, ParseProcessState::PROCESSING)) @@ -130,7 +130,7 @@ void Source::ClangViewParse::parse_initialize() { if(parse_process_state.compare_exchange_strong(expected, ParseProcessState::POSTPROCESSING)) { clang_tokens=clang_tu->get_tokens(0, parse_thread_buffer.bytes()-1); parse_mutex.unlock(); - dispatcher.add([this] { + dispatcher.push([this] { if(parse_mutex.try_lock()) { auto expected=ParseProcessState::POSTPROCESSING; if(parse_process_state.compare_exchange_strong(expected, ParseProcessState::IDLE)) { @@ -149,7 +149,7 @@ void Source::ClangViewParse::parse_initialize() { else { parse_state=ParseState::STOP; parse_mutex.unlock(); - dispatcher.add([this] { + dispatcher.push([this] { Terminal::get().print("Error: failed to reparse "+this->file_path.string()+".\n", true); set_status(""); set_info(""); @@ -876,7 +876,7 @@ void Source::ClangViewAutocomplete::autocomplete() { auto autocomplete_data=std::make_shared >(autocomplete_get_suggestions(buffer->raw(), line_nr, column_nr)); if(parse_state==ParseState::PROCESSING) { - dispatcher.add([this, autocomplete_data] { + dispatcher.push([this, autocomplete_data] { if(autocomplete_state==AutocompleteState::CANCELED) { set_status(""); soft_reparse(); @@ -922,7 +922,7 @@ void Source::ClangViewAutocomplete::autocomplete() { }); } else { - dispatcher.add([this] { + dispatcher.push([this] { Terminal::get().print("Error: autocomplete failed, reparsing "+this->file_path.string()+"\n", true); autocomplete_state=AutocompleteState::CANCELED; full_reparse(); @@ -1002,7 +1002,7 @@ bool Source::ClangViewAutocomplete::full_reparse() { parse_thread.join(); if(autocomplete_thread.joinable()) autocomplete_thread.join(); - dispatcher.add([this] { + dispatcher.push([this] { parse_initialize(); full_reparse_running=false; }); diff --git a/src/terminal.cc b/src/terminal.cc index 0ca760e..66dd536 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -212,13 +212,13 @@ std::shared_ptr Terminal::print_in_progress(std::string st } void Terminal::async_print(const std::string &message, bool bold) { - dispatcher.add([this, message, bold] { + dispatcher.push([this, message, bold] { Terminal::get().print(message, bold); }); } void Terminal::async_print(size_t line_nr, const std::string &message) { - dispatcher.add([this, line_nr, message] { + dispatcher.push([this, line_nr, message] { if(line_nr