Browse Source

Dispatcher cleanup

merge-requests/365/head
eidheim 10 years ago
parent
commit
26b5cab268
  1. 2
      src/directories.cc
  2. 2
      src/dispatcher.cc
  3. 2
      src/dispatcher.h
  4. 4
      src/project.cc
  5. 12
      src/source_clang.cc
  6. 4
      src/terminal.cc

2
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)

2
src/dispatcher.cc

@ -18,7 +18,7 @@ Dispatcher::~Dispatcher() {
functions_mutex.unlock();
}
void Dispatcher::add(std::function<void()> function) {
void Dispatcher::push(std::function<void()> &&function) {
functions_mutex.lock();
functions.emplace_back(function);
functions_mutex.unlock();

2
src/dispatcher.h

@ -13,7 +13,7 @@ private:
public:
Dispatcher();
~Dispatcher();
void add(std::function<void()> function);
void push(std::function<void()> &&function);
void disconnect();
};

4
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;

12
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<std::vector<AutoCompleteData> >(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;
});

4
src/terminal.cc

@ -212,13 +212,13 @@ std::shared_ptr<Terminal::InProgress> 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<deleted_lines)
return;

Loading…
Cancel
Save