From 6afa3a6d6a44a36c48aa64460e48a65d5afcc148 Mon Sep 17 00:00:00 2001 From: vsonnier Date: Sun, 3 Mar 2019 11:42:34 +0100 Subject: [PATCH] Reduced SpinMutex scope in VisualProcessor::distribute() --- src/process/VisualProcessor.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/process/VisualProcessor.h b/src/process/VisualProcessor.h index e79f794..f7a063e 100644 --- a/src/process/VisualProcessor.h +++ b/src/process/VisualProcessor.h @@ -133,11 +133,17 @@ protected: //* \param[in] errorMessage an error message written on std::cout in case pf push timeout. void distribute(OutputDataTypePtr item, std::uint64_t timeout = BLOCKING_INFINITE_TIMEOUT, const char* errorMessage = nullptr) { - std::lock_guard < SpinMutex > busy_lock(busy_update); - //We will try to distribute 'output' among all 'outputs', - //so 'output' will a-priori be shared among all 'outputs'. + //scoped-lock: create a local copy of outputs, and work with it. + std::vector local_outputs; + { + std::lock_guard < SpinMutex > busy_lock(busy_update); + local_outputs = outputs; + } + + //We will try to distribute 'output' among all 'local_outputs', + //so 'output' will a-priori be shared among all 'local_outputs'. - for (VisualOutputQueueTypePtr single_output : outputs) { + for (VisualOutputQueueTypePtr single_output : local_outputs) { //'output' can fail to be given to an single_output, //using a blocking push, with a timeout if (!(single_output)->push(item, timeout, errorMessage)) {