From 6cccbfc73a071409c8da15c9c1ba075b4e8f963c Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 26 Mar 2018 22:13:50 +0200 Subject: [PATCH] Add worker_sync_p function. --- README.md | 5 +++++ m-worker.h | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 18981681..33d6ea7d 100644 --- a/README.md +++ b/README.md @@ -4190,6 +4190,11 @@ If no worker is available, the work order 'func(data)' will be handled by the caller. Otherwise the work order 'func(data)' will be handled by an asynchronous worker. +#### bool worker\_sync\_p(worker\_block\_t syncBlock) + +Test if all work orders registered to this synchronization point are +finished (true) or not (false). + #### void worker\_sync(worker\_block\_t syncBlock) Wait for all work orders registered to this synchronization point to be diff --git a/m-worker.h b/m-worker.h index 41352a0a..a8fd1eb3 100644 --- a/m-worker.h +++ b/m-worker.h @@ -309,15 +309,22 @@ worker_spawn_function(worker_t g, worker_sync_t block, std::functionnum_spawn) == atomic_load (&block->num_terminated_spawn)); +} + /* Wait for all work orders to be finished */ static inline void worker_sync(worker_sync_t block) { //printf ("Waiting for thread terminasion.\n"); - /* If the number of spawns is greated than the number - of terminated spawns, some spawns are still working. - So wait for terminaison */ - while (atomic_load(&block->num_spawn) != atomic_load (&block->num_terminated_spawn)); + while (!worker_sync_p(block)) ; } /* Flush any work order in the queue if some remains.*/