From 090fa399956e08cc719096c229b22eee7beaccf4 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 7 Dec 2021 00:17:57 -0500 Subject: [PATCH] task: don't hold the mutex while disposing of pending Tasks In the event that someday Barrier allows users to force execution of its pending tasks prior to the destruction of the BarrierState object, we'll be ready to submit those Tasks for execution without waiting for the BarrierState mutex lock. Signed-off-by: Zygo Blaxell --- lib/task.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/task.cc b/lib/task.cc index 0c47d3f..00c1dcb 100644 --- a/lib/task.cc +++ b/lib/task.cc @@ -791,11 +791,13 @@ namespace crucible { void BarrierState::release() { + set tasks_local; unique_lock lock(m_mutex); - for (auto i : m_tasks) { + swap(tasks_local, m_tasks); + lock.unlock(); + for (const auto &i : tasks_local) { i.run(); } - m_tasks.clear(); } BarrierState::~BarrierState()