Skip to content

Commit 154ce78

Browse files
committed
Avoid using recursive locks, they indicate poor understanding of code flow.
1 parent 6d6e053 commit 154ce78

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Release/include/cpprest/details/http_server_asio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class hostport_listener
132132
std::map<std::string, web::http::experimental::listener::details::http_listener_impl* > m_listeners;
133133
pplx::extensibility::reader_writer_lock_t m_listeners_lock;
134134

135-
pplx::extensibility::recursive_lock_t m_connections_lock;
135+
std::mutex m_connections_lock;
136136
pplx::extensibility::event_t m_all_connections_complete;
137137
std::set<connection*> m_connections;
138138

Release/src/http/listener/http_server_asio.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ void hostport_listener::on_accept(ip::tcp::socket* socket, const boost::system::
221221
}
222222
else
223223
{
224+
std::lock_guard<std::mutex> lock(m_connections_lock);
224225
{
225-
pplx::scoped_lock<pplx::extensibility::recursive_lock_t> lock(m_connections_lock);
226226
m_connections.insert(new connection(std::unique_ptr<tcp::socket>(std::move(socket)), m_p_server, this, m_is_https, m_ssl_context_callback));
227227
m_all_connections_complete.reset();
228228

@@ -785,7 +785,7 @@ void connection::finish_request_response()
785785
{
786786
// kill the connection
787787
{
788-
pplx::scoped_lock<pplx::extensibility::recursive_lock_t> lock(m_p_parent->m_connections_lock);
788+
std::lock_guard<std::mutex> lock(m_p_parent->m_connections_lock);
789789
m_p_parent->m_connections.erase(this);
790790
if (m_p_parent->m_connections.empty())
791791
{
@@ -801,7 +801,7 @@ void hostport_listener::stop()
801801
{
802802
// halt existing connections
803803
{
804-
pplx::scoped_lock<pplx::extensibility::recursive_lock_t> lock(m_connections_lock);
804+
std::lock_guard<std::mutex> lock(m_connections_lock);
805805
m_acceptor.reset();
806806
for(auto connection : m_connections)
807807
{

0 commit comments

Comments
 (0)