Browse Source

Fixed thread unsafe handlers.erase

merge-requests/365/head
eidheim 8 years ago
parent
commit
97d4558a6b
  1. 8
      src/source_language_protocol.cc

8
src/source_language_protocol.cc

@ -154,10 +154,10 @@ void LanguageProtocol::Client::parse_server_message() {
auto id_it=handlers.find(message_id); auto id_it=handlers.find(message_id);
if(id_it!=handlers.end()) { if(id_it!=handlers.end()) {
auto function=std::move(id_it->second); auto function=std::move(id_it->second);
handlers.erase(id_it->first);
lock.unlock(); lock.unlock();
function(result_it->second, false); function(result_it->second, false);
lock.lock(); lock.lock();
handlers.erase(id_it->first);
} }
} }
} }
@ -168,10 +168,10 @@ void LanguageProtocol::Client::parse_server_message() {
auto id_it=handlers.find(message_id); auto id_it=handlers.find(message_id);
if(id_it!=handlers.end()) { if(id_it!=handlers.end()) {
auto function=std::move(id_it->second); auto function=std::move(id_it->second);
handlers.erase(id_it->first);
lock.unlock(); lock.unlock();
function(result_it->second, true); function(result_it->second, true);
lock.lock(); lock.lock();
handlers.erase(id_it->first);
} }
} }
} }
@ -221,10 +221,10 @@ void LanguageProtocol::Client::write_request(const std::string &method, const st
auto id_it=handlers.find(message_id); auto id_it=handlers.find(message_id);
if(id_it!=handlers.end()) { if(id_it!=handlers.end()) {
auto function=std::move(id_it->second); auto function=std::move(id_it->second);
handlers.erase(id_it->first);
lock.unlock(); lock.unlock();
function(boost::property_tree::ptree(), false); function(boost::property_tree::ptree(), false);
lock.lock(); lock.lock();
handlers.erase(id_it->first);
} }
}); });
} }
@ -236,10 +236,10 @@ void LanguageProtocol::Client::write_request(const std::string &method, const st
auto id_it=handlers.find(message_id); auto id_it=handlers.find(message_id);
if(id_it!=handlers.end()) { if(id_it!=handlers.end()) {
auto function=std::move(id_it->second); auto function=std::move(id_it->second);
handlers.erase(id_it->first);
lock.unlock(); lock.unlock();
function(boost::property_tree::ptree(), false); function(boost::property_tree::ptree(), false);
lock.lock(); lock.lock();
handlers.erase(id_it->first);
} }
} }
} }

Loading…
Cancel
Save