diff --git a/slsReceiverSoftware/src/Fifo.cpp b/slsReceiverSoftware/src/Fifo.cpp index 1bec44e12..6740c8ae2 100644 --- a/slsReceiverSoftware/src/Fifo.cpp +++ b/slsReceiverSoftware/src/Fifo.cpp @@ -81,7 +81,10 @@ void Fifo::DestroyFifos() { fifoStream = nullptr; } -void Fifo::FreeAddress(char *&address) { fifoFree->push(address); } +void Fifo::FreeAddress(char *&address) { + std::lock_guard lock(fifoFreeMutex); + fifoFree->push(address); +} void Fifo::GetNewAddress(char *&address) { int temp = fifoFree->getDataValue(); diff --git a/slsReceiverSoftware/src/Fifo.h b/slsReceiverSoftware/src/Fifo.h index 729ce368b..fe9f3cf1e 100644 --- a/slsReceiverSoftware/src/Fifo.h +++ b/slsReceiverSoftware/src/Fifo.h @@ -16,6 +16,7 @@ #include "sls/sls_detector_defs.h" #include +#include namespace sls { @@ -52,6 +53,9 @@ class Fifo : private virtual slsDetectorDefs { int fifoDepth; std::atomic status_fifoBound; std::atomic status_fifoFree; + /** fifoFree has several producers, CircularFifo allows only one. + * Aligned to avoid false sharing with the members above */ + alignas(128) std::mutex fifoFreeMutex; }; } // namespace sls