Browse Source

Make use of lock_guard instead of unique_lock where possible

merge-requests/393/head
eidheim 7 years ago
parent
commit
5157a3b635
  1. 36
      src/debug_lldb.cc
  2. 4
      src/dispatcher.cc
  3. 2
      src/dispatcher.h
  4. 4
      src/git.cc
  5. 2
      src/project.cc
  6. 6
      src/source_clang.cc
  7. 6
      src/source_diff.cc
  8. 1
      src/source_generic.h
  9. 24
      src/source_language_protocol.cc
  10. 6
      src/terminal.cc
  11. 20
      src/usages_clang.cc

36
src/debug_lldb.cc

@ -250,13 +250,13 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat
} }
void Debug::LLDB::continue_debug() { void Debug::LLDB::continue_debug() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) if(state == lldb::StateType::eStateStopped)
process->Continue(); process->Continue();
} }
void Debug::LLDB::stop() { void Debug::LLDB::stop() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateRunning) { if(state == lldb::StateType::eStateRunning) {
auto error = process->Stop(); auto error = process->Stop();
if(error.Fail()) if(error.Fail())
@ -265,7 +265,7 @@ void Debug::LLDB::stop() {
} }
void Debug::LLDB::kill() { void Debug::LLDB::kill() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(process) { if(process) {
auto error = process->Kill(); auto error = process->Kill();
if(error.Fail()) if(error.Fail())
@ -274,21 +274,21 @@ void Debug::LLDB::kill() {
} }
void Debug::LLDB::step_over() { void Debug::LLDB::step_over() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {
process->GetSelectedThread().StepOver(); process->GetSelectedThread().StepOver();
} }
} }
void Debug::LLDB::step_into() { void Debug::LLDB::step_into() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {
process->GetSelectedThread().StepInto(); process->GetSelectedThread().StepInto();
} }
} }
void Debug::LLDB::step_out() { void Debug::LLDB::step_out() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {
process->GetSelectedThread().StepOut(); process->GetSelectedThread().StepOut();
} }
@ -296,7 +296,7 @@ void Debug::LLDB::step_out() {
std::pair<std::string, std::string> Debug::LLDB::run_command(const std::string &command) { std::pair<std::string, std::string> Debug::LLDB::run_command(const std::string &command) {
std::pair<std::string, std::string> command_return; std::pair<std::string, std::string> command_return;
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped || state == lldb::StateType::eStateRunning) { if(state == lldb::StateType::eStateStopped || state == lldb::StateType::eStateRunning) {
lldb::SBCommandReturnObject command_return_object; lldb::SBCommandReturnObject command_return_object;
debugger->GetCommandInterpreter().HandleCommand(command.c_str(), command_return_object, true); debugger->GetCommandInterpreter().HandleCommand(command.c_str(), command_return_object, true);
@ -312,7 +312,7 @@ std::pair<std::string, std::string> Debug::LLDB::run_command(const std::string &
std::vector<Debug::LLDB::Frame> Debug::LLDB::get_backtrace() { std::vector<Debug::LLDB::Frame> Debug::LLDB::get_backtrace() {
std::vector<Frame> backtrace; std::vector<Frame> backtrace;
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {
auto thread = process->GetSelectedThread(); auto thread = process->GetSelectedThread();
for(uint32_t c_f = 0; c_f < thread.GetNumFrames(); c_f++) { for(uint32_t c_f = 0; c_f < thread.GetNumFrames(); c_f++) {
@ -348,7 +348,7 @@ std::vector<Debug::LLDB::Frame> Debug::LLDB::get_backtrace() {
std::vector<Debug::LLDB::Variable> Debug::LLDB::get_variables() { std::vector<Debug::LLDB::Variable> Debug::LLDB::get_variables() {
std::vector<Debug::LLDB::Variable> variables; std::vector<Debug::LLDB::Variable> variables;
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {
for(uint32_t c_t = 0; c_t < process->GetNumThreads(); c_t++) { for(uint32_t c_t = 0; c_t < process->GetNumThreads(); c_t++) {
auto thread = process->GetThreadAtIndex(c_t); auto thread = process->GetThreadAtIndex(c_t);
@ -402,7 +402,7 @@ std::vector<Debug::LLDB::Variable> Debug::LLDB::get_variables() {
} }
void Debug::LLDB::select_frame(uint32_t frame_index, uint32_t thread_index_id) { void Debug::LLDB::select_frame(uint32_t frame_index, uint32_t thread_index_id) {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {
if(thread_index_id != 0) if(thread_index_id != 0)
process->SetSelectedThreadByIndexID(thread_index_id); process->SetSelectedThreadByIndexID(thread_index_id);
@ -419,7 +419,7 @@ void Debug::LLDB::cancel() {
std::string Debug::LLDB::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) { std::string Debug::LLDB::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) {
std::string variable_value; std::string variable_value;
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {
auto frame = process->GetSelectedThread().GetSelectedFrame(); auto frame = process->GetSelectedThread().GetSelectedFrame();
@ -462,7 +462,7 @@ std::string Debug::LLDB::get_value(const std::string &variable, const boost::fil
std::string Debug::LLDB::get_return_value(const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) { std::string Debug::LLDB::get_return_value(const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) {
std::string return_value; std::string return_value;
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {
auto thread = process->GetSelectedThread(); auto thread = process->GetSelectedThread();
auto thread_return_value = thread.GetStopReturnValue(); auto thread_return_value = thread.GetStopReturnValue();
@ -484,22 +484,22 @@ std::string Debug::LLDB::get_return_value(const boost::filesystem::path &file_pa
} }
bool Debug::LLDB::is_invalid() { bool Debug::LLDB::is_invalid() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
return state == lldb::StateType::eStateInvalid; return state == lldb::StateType::eStateInvalid;
} }
bool Debug::LLDB::is_stopped() { bool Debug::LLDB::is_stopped() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
return state == lldb::StateType::eStateStopped; return state == lldb::StateType::eStateStopped;
} }
bool Debug::LLDB::is_running() { bool Debug::LLDB::is_running() {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
return state == lldb::StateType::eStateRunning; return state == lldb::StateType::eStateRunning;
} }
void Debug::LLDB::add_breakpoint(const boost::filesystem::path &file_path, int line_nr) { void Debug::LLDB::add_breakpoint(const boost::filesystem::path &file_path, int line_nr) {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::eStateStopped || state == lldb::eStateRunning) { if(state == lldb::eStateStopped || state == lldb::eStateRunning) {
if(!(process->GetTarget().BreakpointCreateByLocation(file_path.string().c_str(), line_nr)).IsValid()) if(!(process->GetTarget().BreakpointCreateByLocation(file_path.string().c_str(), line_nr)).IsValid())
Terminal::get().async_print("Error (debug): Could not create breakpoint at: " + file_path.string() + ":" + std::to_string(line_nr) + '\n', true); Terminal::get().async_print("Error (debug): Could not create breakpoint at: " + file_path.string() + ":" + std::to_string(line_nr) + '\n', true);
@ -507,7 +507,7 @@ void Debug::LLDB::add_breakpoint(const boost::filesystem::path &file_path, int l
} }
void Debug::LLDB::remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) { void Debug::LLDB::remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::eStateStopped || state == lldb::eStateRunning) { if(state == lldb::eStateStopped || state == lldb::eStateRunning) {
auto target = process->GetTarget(); auto target = process->GetTarget();
for(int line_nr_try = line_nr; line_nr_try < line_count; line_nr_try++) { for(int line_nr_try = line_nr; line_nr_try < line_count; line_nr_try++) {
@ -532,7 +532,7 @@ void Debug::LLDB::remove_breakpoint(const boost::filesystem::path &file_path, in
} }
void Debug::LLDB::write(const std::string &buffer) { void Debug::LLDB::write(const std::string &buffer) {
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(state == lldb::StateType::eStateRunning) { if(state == lldb::StateType::eStateRunning) {
process->PutSTDIN(buffer.c_str(), buffer.size()); process->PutSTDIN(buffer.c_str(), buffer.size());
} }

4
src/dispatcher.cc

@ -5,7 +5,7 @@ Dispatcher::Dispatcher() {
connection = dispatcher.connect([this] { connection = dispatcher.connect([this] {
std::vector<std::list<std::function<void()>>::iterator> its; std::vector<std::list<std::function<void()>>::iterator> its;
{ {
std::unique_lock<std::mutex> lock(functions_mutex); std::lock_guard<std::mutex> lock(functions_mutex);
if(functions.empty()) if(functions.empty())
return; return;
its.reserve(functions.size()); its.reserve(functions.size());
@ -15,7 +15,7 @@ Dispatcher::Dispatcher() {
for(auto &it : its) for(auto &it : its)
(*it)(); (*it)();
{ {
std::unique_lock<std::mutex> lock(functions_mutex); std::lock_guard<std::mutex> lock(functions_mutex);
for(auto &it : its) for(auto &it : its)
functions.erase(it); functions.erase(it);
} }

2
src/dispatcher.h

@ -18,7 +18,7 @@ public:
template <typename T> template <typename T>
void post(T &&function) { void post(T &&function) {
{ {
std::unique_lock<std::mutex> lock(functions_mutex); std::lock_guard<std::mutex> lock(functions_mutex);
functions.emplace_back(std::forward<T>(function)); functions.emplace_back(std::forward<T>(function));
} }
dispatcher(); dispatcher();

4
src/git.cc

@ -182,7 +182,7 @@ int Git::Repository::status_callback(const char *path, unsigned int status_flags
Git::Repository::Status Git::Repository::get_status() { Git::Repository::Status Git::Repository::get_status() {
{ {
std::unique_lock<std::mutex> lock(saved_status_mutex); std::lock_guard<std::mutex> lock(saved_status_mutex);
if(has_saved_status) if(has_saved_status)
return saved_status; return saved_status;
} }
@ -217,7 +217,7 @@ Git::Repository::Status Git::Repository::get_status() {
} }
void Git::Repository::clear_saved_status() { void Git::Repository::clear_saved_status() {
std::unique_lock<std::mutex> lock(saved_status_mutex); std::lock_guard<std::mutex> lock(saved_status_mutex);
saved_status.added.clear(); saved_status.added.clear();
saved_status.modified.clear(); saved_status.modified.clear();
has_saved_status = false; has_saved_status = false;

2
src/project.cc

@ -409,7 +409,7 @@ void Project::LLDB::debug_start() {
boost::filesystem::path stop_path; boost::filesystem::path stop_path;
unsigned stop_line = 0, stop_column = 0; unsigned stop_line = 0, stop_column = 0;
std::unique_lock<std::mutex> lock(Debug::LLDB::get().mutex); std::lock_guard<std::mutex> lock(Debug::LLDB::get().mutex);
auto process = lldb::SBProcess::GetProcessFromEvent(event); auto process = lldb::SBProcess::GetProcessFromEvent(event);
auto state = lldb::SBProcess::GetStateFromEvent(event); auto state = lldb::SBProcess::GetStateFromEvent(event);
lldb::SBStream stream; lldb::SBStream stream;

6
src/source_clang.cc

@ -550,7 +550,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
std::smatch sm; std::smatch sm;
if(std::regex_match(line, sm, regex)) { if(std::regex_match(line, sm, regex)) {
{ {
std::unique_lock<std::mutex> lock(autocomplete.prefix_mutex); std::lock_guard<std::mutex> lock(autocomplete.prefix_mutex);
autocomplete.prefix = sm.length(2) ? sm[3].str() : sm.length(4) ? sm[5].str() : sm[6].str(); autocomplete.prefix = sm.length(2) ? sm[3].str() : sm.length(4) ? sm[5].str() : sm[6].str();
if(!sm.length(2) && !sm.length(4)) if(!sm.length(2) && !sm.length(4))
enable_snippets = true; enable_snippets = true;
@ -559,7 +559,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
} }
else if(is_possible_argument()) { else if(is_possible_argument()) {
show_parameters = true; show_parameters = true;
std::unique_lock<std::mutex> lock(autocomplete.prefix_mutex); std::lock_guard<std::mutex> lock(autocomplete.prefix_mutex);
autocomplete.prefix = ""; autocomplete.prefix = "";
return true; return true;
} }
@ -572,7 +572,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
iter.forward_char(); iter.forward_char();
{ {
std::unique_lock<std::mutex> lock(autocomplete.prefix_mutex); std::lock_guard<std::mutex> lock(autocomplete.prefix_mutex);
autocomplete.prefix = get_buffer()->get_text(iter, end_iter); autocomplete.prefix = get_buffer()->get_text(iter, end_iter);
} }
auto prev1 = iter; auto prev1 = iter;

6
src/source_diff.cc

@ -149,7 +149,7 @@ void Source::DiffView::configure() {
delayed_monitor_changed_connection = Glib::signal_timeout().connect([this]() { delayed_monitor_changed_connection = Glib::signal_timeout().connect([this]() {
monitor_changed = true; monitor_changed = true;
parse_state = ParseState::STARTING; parse_state = ParseState::STARTING;
std::unique_lock<std::mutex> lock(parse_mutex); std::lock_guard<std::mutex> lock(parse_mutex);
diff = nullptr; diff = nullptr;
return false; return false;
}, 500); }, 500);
@ -298,7 +298,7 @@ std::string Source::DiffView::git_get_diff_details() {
auto iter = get_buffer()->get_iter_at_line(line_nr); auto iter = get_buffer()->get_iter_at_line(line_nr);
if(iter.has_tag(renderer->tag_removed_above)) if(iter.has_tag(renderer->tag_removed_above))
--line_nr; --line_nr;
std::unique_lock<std::mutex> lock(parse_mutex); std::lock_guard<std::mutex> lock(parse_mutex);
parse_buffer = get_buffer()->get_text(); parse_buffer = get_buffer()->get_text();
details = diff->get_details(parse_buffer.raw(), line_nr); details = diff->get_details(parse_buffer.raw(), line_nr);
} }
@ -312,7 +312,7 @@ std::unique_ptr<Git::Repository::Diff> Source::DiffView::get_diff() {
auto work_path = filesystem::get_normal_path(repository->get_work_path()); auto work_path = filesystem::get_normal_path(repository->get_work_path());
boost::filesystem::path relative_path; boost::filesystem::path relative_path;
{ {
std::unique_lock<std::mutex> lock(canonical_file_path_mutex); std::lock_guard<std::mutex> lock(canonical_file_path_mutex);
if(!filesystem::file_in_path(canonical_file_path, work_path)) if(!filesystem::file_in_path(canonical_file_path, work_path))
throw std::runtime_error("not a relative path"); throw std::runtime_error("not a relative path");
relative_path = filesystem::get_relative_path(canonical_file_path, work_path); relative_path = filesystem::get_relative_path(canonical_file_path, work_path);

1
src/source_generic.h

@ -19,6 +19,7 @@ namespace Source {
std::pair<Gtk::TextIter, Gtk::TextIter> get_word(Gtk::TextIter iter); std::pair<Gtk::TextIter, Gtk::TextIter> get_word(Gtk::TextIter iter);
std::vector<std::pair<Gtk::TextIter, Gtk::TextIter>> get_words(const Gtk::TextIter &start, const Gtk::TextIter &end); std::vector<std::pair<Gtk::TextIter, Gtk::TextIter>> get_words(const Gtk::TextIter &start, const Gtk::TextIter &end);
std::mutex buffer_words_mutex;
std::map<std::string, size_t> buffer_words; std::map<std::string, size_t> buffer_words;
void setup_buffer_words(); void setup_buffer_words();
std::atomic<bool> show_prefix_buffer_word = {false}; /// To avoid showing the current word if it is unique in document std::atomic<bool> show_prefix_buffer_word = {false}; /// To avoid showing the current word if it is unique in document

24
src/source_language_protocol.cc

@ -85,7 +85,7 @@ LanguageProtocol::Client::~Client() {
}); });
result_processed.get_future().get(); result_processed.get_future().get();
std::unique_lock<std::mutex> lock(timeout_threads_mutex); std::lock_guard<std::mutex> lock(timeout_threads_mutex);
for(auto &thread : timeout_threads) for(auto &thread : timeout_threads)
thread.join(); thread.join();
@ -103,7 +103,7 @@ LanguageProtocol::Client::~Client() {
LanguageProtocol::Capabilities LanguageProtocol::Client::initialize(Source::LanguageProtocolView *view) { LanguageProtocol::Capabilities LanguageProtocol::Client::initialize(Source::LanguageProtocolView *view) {
if(view) { if(view) {
std::unique_lock<std::mutex> lock(views_mutex); std::lock_guard<std::mutex> lock(views_mutex);
views.emplace(view); views.emplace(view);
} }
@ -145,12 +145,12 @@ LanguageProtocol::Capabilities LanguageProtocol::Client::initialize(Source::Lang
void LanguageProtocol::Client::close(Source::LanguageProtocolView *view) { void LanguageProtocol::Client::close(Source::LanguageProtocolView *view) {
{ {
std::unique_lock<std::mutex> lock(views_mutex); std::lock_guard<std::mutex> lock(views_mutex);
auto it = views.find(view); auto it = views.find(view);
if(it != views.end()) if(it != views.end())
views.erase(it); views.erase(it);
} }
std::unique_lock<std::mutex> lock(read_write_mutex); std::lock_guard<std::mutex> lock(read_write_mutex);
for(auto it = handlers.begin(); it != handlers.end();) { for(auto it = handlers.begin(); it != handlers.end();) {
if(it->second.first == view) if(it->second.first == view)
it = handlers.erase(it); it = handlers.erase(it);
@ -272,11 +272,11 @@ void LanguageProtocol::Client::write_request(Source::LanguageProtocolView *view,
handlers.emplace(message_id, std::make_pair(view, std::move(function))); handlers.emplace(message_id, std::make_pair(view, std::move(function)));
auto message_id = this->message_id; auto message_id = this->message_id;
std::unique_lock<std::mutex> lock(timeout_threads_mutex); std::lock_guard<std::mutex> lock(timeout_threads_mutex);
timeout_threads.emplace_back([this, message_id] { timeout_threads.emplace_back([this, message_id] {
for(size_t c = 0; c < 20; ++c) { for(size_t c = 0; c < 20; ++c) {
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::unique_lock<std::mutex> lock(read_write_mutex); std::lock_guard<std::mutex> lock(read_write_mutex);
auto id_it = handlers.find(message_id); auto id_it = handlers.find(message_id);
if(id_it == handlers.end()) if(id_it == handlers.end())
return; return;
@ -311,7 +311,7 @@ void LanguageProtocol::Client::write_request(Source::LanguageProtocolView *view,
} }
void LanguageProtocol::Client::write_notification(const std::string &method, const std::string &params) { void LanguageProtocol::Client::write_notification(const std::string &method, const std::string &params) {
std::unique_lock<std::mutex> lock(read_write_mutex); std::lock_guard<std::mutex> lock(read_write_mutex);
std::string content(R"({"jsonrpc":"2.0","method":")" + method + R"(","params":{)" + params + "}}"); std::string content(R"({"jsonrpc":"2.0","method":")" + method + R"(","params":{)" + params + "}}");
auto message = "Content-Length: " + std::to_string(content.size()) + "\r\n\r\n" + content; auto message = "Content-Length: " + std::to_string(content.size()) + "\r\n\r\n" + content;
if(Config::get().log.language_server) if(Config::get().log.language_server)
@ -332,7 +332,7 @@ void LanguageProtocol::Client::handle_server_request(const std::string &method,
catch(...) { catch(...) {
} }
} }
std::unique_lock<std::mutex> lock(views_mutex); std::lock_guard<std::mutex> lock(views_mutex);
for(auto view : views) { for(auto view : views) {
if(uri.size() >= 7 && uri.compare(7, std::string::npos, view->file_path.string()) == 0) { if(uri.size() >= 7 && uri.compare(7, std::string::npos, view->file_path.string()) == 0) {
view->update_diagnostics(std::move(diagnostics)); view->update_diagnostics(std::move(diagnostics));
@ -1261,7 +1261,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
std::smatch sm; std::smatch sm;
if(std::regex_match(line, sm, regex)) { if(std::regex_match(line, sm, regex)) {
{ {
std::unique_lock<std::mutex> lock(autocomplete.prefix_mutex); std::lock_guard<std::mutex> lock(autocomplete.prefix_mutex);
autocomplete.prefix = sm.length(2) ? sm[3].str() : sm.length(4) ? sm[5].str() : sm[6].str(); autocomplete.prefix = sm.length(2) ? sm[3].str() : sm.length(4) ? sm[5].str() : sm[6].str();
if(!sm.length(2) && !sm.length(4)) if(!sm.length(2) && !sm.length(4))
autocomplete_enable_snippets = true; autocomplete_enable_snippets = true;
@ -1270,7 +1270,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
} }
else if(is_possible_argument()) { else if(is_possible_argument()) {
autocomplete_show_parameters = true; autocomplete_show_parameters = true;
std::unique_lock<std::mutex> lock(autocomplete.prefix_mutex); std::lock_guard<std::mutex> lock(autocomplete.prefix_mutex);
autocomplete.prefix = ""; autocomplete.prefix = "";
return true; return true;
} }
@ -1283,7 +1283,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
iter.forward_char(); iter.forward_char();
{ {
std::unique_lock<std::mutex> lock(autocomplete.prefix_mutex); std::lock_guard<std::mutex> lock(autocomplete.prefix_mutex);
autocomplete.prefix = get_buffer()->get_text(iter, end_iter); autocomplete.prefix = get_buffer()->get_text(iter, end_iter);
} }
auto prev1 = iter; auto prev1 = iter;
@ -1401,7 +1401,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
if(autocomplete_enable_snippets) { if(autocomplete_enable_snippets) {
std::string prefix; std::string prefix;
{ {
std::unique_lock<std::mutex> lock(autocomplete.prefix_mutex); std::lock_guard<std::mutex> lock(autocomplete.prefix_mutex);
prefix = autocomplete.prefix; prefix = autocomplete.prefix;
} }
std::lock_guard<std::mutex> lock(snippets_mutex); std::lock_guard<std::mutex> lock(snippets_mutex);

6
src/terminal.cc

@ -120,7 +120,7 @@ void Terminal::async_process(const std::string &command, const boost::filesystem
} }
void Terminal::kill_last_async_process(bool force) { void Terminal::kill_last_async_process(bool force) {
std::unique_lock<std::mutex> lock(processes_mutex); std::lock_guard<std::mutex> lock(processes_mutex);
if(processes.empty()) if(processes.empty())
Info::get().print("No running processes"); Info::get().print("No running processes");
else else
@ -128,7 +128,7 @@ void Terminal::kill_last_async_process(bool force) {
} }
void Terminal::kill_async_processes(bool force) { void Terminal::kill_async_processes(bool force) {
std::unique_lock<std::mutex> lock(processes_mutex); std::lock_guard<std::mutex> lock(processes_mutex);
for(auto &process : processes) for(auto &process : processes)
process->kill(force); process->kill(force);
} }
@ -393,7 +393,7 @@ bool Terminal::on_button_press_event(GdkEventButton *button_event) {
} }
bool Terminal::on_key_press_event(GdkEventKey *event) { bool Terminal::on_key_press_event(GdkEventKey *event) {
std::unique_lock<std::mutex> lock(processes_mutex); std::lock_guard<std::mutex> lock(processes_mutex);
bool debug_is_running = false; bool debug_is_running = false;
#ifdef JUCI_ENABLE_DEBUG #ifdef JUCI_ENABLE_DEBUG
debug_is_running = Project::current ? Project::current->debug_is_running() : false; debug_is_running = Project::current ? Project::current->debug_is_running() : false;

20
src/usages_clang.cc

@ -170,7 +170,7 @@ std::vector<Usages::Clang::Usages> Usages::Clang::get_usages(const boost::filesy
// Use cache // Use cache
for(auto it = potential_paths.begin(); it != potential_paths.end();) { for(auto it = potential_paths.begin(); it != potential_paths.end();) {
std::unique_lock<std::mutex> lock(caches_mutex); std::lock_guard<std::mutex> lock(caches_mutex);
auto caches_it = caches.find(*it); auto caches_it = caches.find(*it);
// Load cache from file if not found in memory and if cache file exists // Load cache from file if not found in memory and if cache file exists
@ -222,7 +222,7 @@ std::vector<Usages::Clang::Usages> Usages::Clang::get_usages(const boost::filesy
boost::filesystem::path path; boost::filesystem::path path;
{ {
static std::mutex mutex; static std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if(it == potential_paths.end()) if(it == potential_paths.end())
return; return;
path = *it; path = *it;
@ -231,7 +231,7 @@ std::vector<Usages::Clang::Usages> Usages::Clang::get_usages(const boost::filesy
{ {
static std::mutex mutex; static std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
// std::cout << "parsing: " << path << std::endl; // std::cout << "parsing: " << path << std::endl;
} }
// auto before_time = std::chrono::system_clock::now(); // auto before_time = std::chrono::system_clock::now();
@ -258,7 +258,7 @@ std::vector<Usages::Clang::Usages> Usages::Clang::get_usages(const boost::filesy
{ {
static std::mutex mutex; static std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
add_usages(project_path, build_path, path, usages, visited, spelling, cursor, &translation_unit, true); add_usages(project_path, build_path, path, usages, visited, spelling, cursor, &translation_unit, true);
add_usages_from_includes(project_path, build_path, usages, visited, spelling, cursor, &translation_unit, true); add_usages_from_includes(project_path, build_path, usages, visited, spelling, cursor, &translation_unit, true);
} }
@ -295,7 +295,7 @@ void Usages::Clang::cache(const boost::filesystem::path &project_path, const boo
return; return;
{ {
std::unique_lock<std::mutex> lock(caches_mutex); std::lock_guard<std::mutex> lock(caches_mutex);
if(project_paths_in_use.count(project_path)) { if(project_paths_in_use.count(project_path)) {
caches.erase(path); caches.erase(path);
caches.emplace(path, Cache(project_path, build_path, path, before_parse_time, translation_unit, tokens)); caches.emplace(path, Cache(project_path, build_path, path, before_parse_time, translation_unit, tokens));
@ -330,7 +330,7 @@ void Usages::Clang::cache(const boost::filesystem::path &project_path, const boo
if(file_size == static_cast<boost::uintmax_t>(-1) || ec) if(file_size == static_cast<boost::uintmax_t>(-1) || ec)
continue; continue;
auto tokens = translation_unit->get_tokens(path.string(), 0, file_size - 1); auto tokens = translation_unit->get_tokens(path.string(), 0, file_size - 1);
std::unique_lock<std::mutex> lock(caches_mutex); std::lock_guard<std::mutex> lock(caches_mutex);
if(project_paths_in_use.count(project_path)) { if(project_paths_in_use.count(project_path)) {
caches.erase(path); caches.erase(path);
caches.emplace(path, Cache(project_path, build_path, path, before_parse_time, translation_unit, tokens.get())); caches.emplace(path, Cache(project_path, build_path, path, before_parse_time, translation_unit, tokens.get()));
@ -341,7 +341,7 @@ void Usages::Clang::cache(const boost::filesystem::path &project_path, const boo
} }
void Usages::Clang::erase_unused_caches(const PathSet &project_paths_in_use) { void Usages::Clang::erase_unused_caches(const PathSet &project_paths_in_use) {
std::unique_lock<std::mutex> lock(caches_mutex); std::lock_guard<std::mutex> lock(caches_mutex);
for(auto it = caches.begin(); it != caches.end();) { for(auto it = caches.begin(); it != caches.end();) {
bool found = false; bool found = false;
for(auto &project_path : project_paths_in_use) { for(auto &project_path : project_paths_in_use) {
@ -360,7 +360,7 @@ void Usages::Clang::erase_unused_caches(const PathSet &project_paths_in_use) {
} }
void Usages::Clang::erase_cache(const boost::filesystem::path &path) { void Usages::Clang::erase_cache(const boost::filesystem::path &path) {
std::unique_lock<std::mutex> lock(caches_mutex); std::lock_guard<std::mutex> lock(caches_mutex);
auto it = caches.find(path); auto it = caches.find(path);
if(it == caches.end()) if(it == caches.end())
@ -378,7 +378,7 @@ void Usages::Clang::erase_all_caches_for_project(const boost::filesystem::path &
if(cache_in_progress_count != 0) if(cache_in_progress_count != 0)
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
std::unique_lock<std::mutex> lock(caches_mutex); std::lock_guard<std::mutex> lock(caches_mutex);
boost::system::error_code ec; boost::system::error_code ec;
auto usages_clang_path = build_path / cache_folder; auto usages_clang_path = build_path / cache_folder;
if(boost::filesystem::exists(usages_clang_path, ec) && boost::filesystem::is_directory(usages_clang_path, ec)) { if(boost::filesystem::exists(usages_clang_path, ec) && boost::filesystem::is_directory(usages_clang_path, ec)) {
@ -441,7 +441,7 @@ void Usages::Clang::add_usages(const boost::filesystem::path &project_path, cons
} }
if(store_in_cache && filesystem::file_in_path(path, project_path)) { if(store_in_cache && filesystem::file_in_path(path, project_path)) {
std::unique_lock<std::mutex> lock(caches_mutex); std::lock_guard<std::mutex> lock(caches_mutex);
caches.erase(path); caches.erase(path);
caches.emplace(path, Cache(project_path, build_path, path, before_parse_time, translation_unit, tokens.get())); caches.emplace(path, Cache(project_path, build_path, path, before_parse_time, translation_unit, tokens.get()));
} }

Loading…
Cancel
Save