@@ -153,6 +153,8 @@ void populate_result(const std::string &url, cluster* owner, http_request_comple
153153/* Returns true if the request has been made */
154154bool http_request::is_completed ()
155155{
156+ // For some odd reason, BSD requires this to have a lock to prevent data races even though `completed` is std::atomic.
157+ std::unique_lock<std::mutex> lock (this_captured_mutex);
156158 return completed;
157159}
158160
@@ -281,8 +283,8 @@ http_request_completion_t http_request::run(request_concurrency_queue* processor
281283 {
282284 std::lock_guard<std::mutex> lock (this_captured_mutex);
283285 this_captured = false ;
286+ this_captured_signal.notify_all ();
284287 }
285- this_captured_signal.notify_all ();
286288 });
287289 }
288290 );
@@ -317,7 +319,7 @@ request_concurrency_queue::request_concurrency_queue(class cluster* owner, class
317319 tick_and_deliver_requests (in_index);
318320 /* Clear pending removals in the removals queue */
319321 if (time (nullptr ) % 90 == 0 ) {
320- std::scoped_lock lock1{in_mutex };
322+ std::scoped_lock lock1{rem_mutex };
321323 for (auto it = removals.cbegin (); it != removals.cend ();) {
322324 if ((*it)->is_completed ()) {
323325 it = removals.erase (it);
@@ -409,6 +411,7 @@ void request_concurrency_queue::tick_and_deliver_requests(uint32_t index)
409411 {
410412 /* Find the owned pointer in requests_in */
411413 std::scoped_lock lock1{in_mutex};
414+ std::scoped_lock lock2{rem_mutex};
412415
413416 const std::string &key = request_view->endpoint ;
414417 auto [begin, end] = std::equal_range (requests_in.begin (), requests_in.end (), key, compare_request{});
0 commit comments