Skip to content

Commit 45e3f2e

Browse files
committed
fix
1 parent 21a6c92 commit 45e3f2e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

examples/server/server.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,28 +1666,28 @@ struct server_response {
16661666

16671667
// add the id_task to the list of tasks waiting for response
16681668
void add_waiting_task_id(int id_task) {
1669-
SRV_DBG("add task %d to waiting list. current waiting = %d (before add)\n", id_task, (int) waiting_task_ids.size());
1669+
SRV_DBG("add task %d to waiting list. current no waiting = %d (before add)\n", id_task, queue_results.cbegin() == queue_results.cend() ? 0 : 1);
16701670
waiting_task_ids.insert(id_task, 0);
16711671
}
16721672

16731673
void add_waiting_tasks(const std::vector<server_task> & tasks) {
16741674
for (const auto & task : tasks) {
1675-
SRV_DBG("add task %d to waiting list. current waiting = %d (before add)\n", task.id, (int) waiting_task_ids.size());
1675+
SRV_DBG("add task %d to waiting list. current no waiting = %d (before add)\n", task.id, queue_results.cbegin() == queue_results.cend() ? 0 : 1);
16761676
waiting_task_ids.insert(task.id, 0);
16771677
}
16781678
}
16791679

16801680
// when the request is finished, we can remove task associated with it
16811681
void remove_waiting_task_id(int id_task) {
1682-
SRV_DBG("remove task %d from waiting list. current waiting = %d (before remove)\n", id_task, (int) waiting_task_ids.size());
1682+
SRV_DBG("remove task %d from waiting list. current no waiting = %d (before remove)\n", id_task, queue_results.cbegin() == queue_results.cend() ? 0 : 1);
16831683
waiting_task_ids.erase(id_task);
16841684
// make sure to clean up all pending results
16851685
queue_results.erase(id_task);
16861686
}
16871687

16881688
void remove_waiting_task_ids(const std::unordered_set<int> & id_tasks) {
16891689
for (const auto & id_task : id_tasks) {
1690-
SRV_DBG("remove task %d from waiting list. current waiting = %d (before remove)\n", id_task, (int) waiting_task_ids.size());
1690+
SRV_DBG("remove task %d from waiting list. current no waiting = %d (before remove)\n", id_task, queue_results.cbegin() == queue_results.cend() ? 0 : 1);
16911691
waiting_task_ids.erase(id_task);
16921692
}
16931693
}
@@ -1704,7 +1704,8 @@ struct server_response {
17041704
}
17051705
}
17061706

1707-
condition_results.wait(mutex_results, [&]{
1707+
std::lock_guard<std::mutex> lock(mutex_results);
1708+
condition_results.wait(lock, [&]{
17081709
return queue_results.cbegin() != queue_results.cend();
17091710
});
17101711
}
@@ -1733,7 +1734,7 @@ struct server_response {
17331734

17341735
// should never reach here
17351736
}
1736-
1737+
17371738
// single-task version of recv()
17381739
server_task_result_ptr recv(int id_task) {
17391740
while (true) {

0 commit comments

Comments
 (0)