]> git.hungrycats.org Git - bees/commitdiff
task: don't hold the mutex while disposing of pending Tasks
authorZygo Blaxell <bees@furryterror.org>
Tue, 7 Dec 2021 05:17:57 +0000 (00:17 -0500)
committerZygo Blaxell <bees@furryterror.org>
Wed, 21 Dec 2022 01:50:56 +0000 (20:50 -0500)
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 <bees@furryterror.org>
lib/task.cc

index 0c47d3fd4f4c4b39e7817724d707df9a301d83ba..00c1dcbed19e8fb11bc45df44324e8cf0c51e22b 100644 (file)
@@ -791,11 +791,13 @@ namespace crucible {
        void
        BarrierState::release()
        {
+               set<Task> tasks_local;
                unique_lock<mutex> 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()