Skip to content
Snippets Groups Projects
Commit 00444dea authored by Anton Piccardo-Selg's avatar Anton Piccardo-Selg
Browse files

Refs #15288 Change mutex for BoxControllerNexusIO

parent f4019432
No related merge requests found
......@@ -4,7 +4,6 @@
#include "MantidAPI/IBoxControllerIO.h"
#include "MantidAPI/BoxController.h"
#include "MantidKernel/DiskBuffer.h"
#include <Poco/Mutex.h>
#include <nexus/NeXusFile.hpp>
namespace Mantid {
......@@ -102,9 +101,8 @@ private:
/// the vector, which describes the event specific data size, namely how many
/// column an event is composed into and this class reads/writres
std::vector<int64_t> m_BlockSize;
/// lock Nexus file operations as Nexus is not thread safe // Poco::Mutex -- >
/// is recursive.
mutable Poco::FastMutex m_fileMutex;
/// lock Nexus file operations as Nexus is not thread safe
mutable Mantid::Kernel::Mutex m_fileMutex;
// Mainly static information which may be split into different IO classes
// selected through chein of responsibility.
......
......@@ -116,7 +116,7 @@ bool BoxControllerNeXusIO::openFile(const std::string &fileName,
if (m_File)
return false;
Poco::ScopedLock<Poco::FastMutex> _lock(m_fileMutex);
Mantid::Kernel::LockGuardMutex _lock(m_fileMutex);
m_ReadOnly = true;
if (mode.find("w") != std::string::npos ||
mode.find("W") != std::string::npos) {
......@@ -332,7 +332,7 @@ void BoxControllerNeXusIO::saveGenericBlock(
// Specify the dimensions
std::vector<int64_t> dims(m_BlockSize);
Poco::ScopedLock<Poco::FastMutex> _lock(m_fileMutex);
Mantid::Kernel::LockGuardMutex _lock(m_fileMutex);
start[0] = int64_t(blockPosition);
dims[0] = int64_t(DataBlock.size() / this->getNDataColums());
......@@ -384,7 +384,7 @@ void BoxControllerNeXusIO::loadGenericBlock(std::vector<Type> &Block,
std::vector<int64_t> start(2, 0);
std::vector<int64_t> size(m_BlockSize);
Poco::ScopedLock<Poco::FastMutex> _lock(m_fileMutex);
Mantid::Kernel::LockGuardMutex _lock(m_fileMutex);
start[0] = static_cast<int64_t>(blockPosition);
size[0] = static_cast<int64_t>(nPoints);
......@@ -457,7 +457,7 @@ void BoxControllerNeXusIO::loadBlock(std::vector<double> &Block,
/// Clear NeXus internal cache
void BoxControllerNeXusIO::flushData() const {
Poco::ScopedLock<Poco::FastMutex> _lock(m_fileMutex);
Mantid::Kernel::LockGuardMutex _lock(m_fileMutex);
m_File->flush();
}
/** flush disk buffer data from memory and close underlying NeXus file*/
......@@ -466,7 +466,7 @@ void BoxControllerNeXusIO::closeFile() {
// write all file-backed data still stack in the data buffer into the file.
this->flushCache();
// lock file
Poco::ScopedLock<Poco::FastMutex> _lock(m_fileMutex);
Mantid::Kernel::LockGuardMutex _lock(m_fileMutex);
{
m_File->closeData(); // close events data
......
......@@ -4,8 +4,6 @@
namespace Mantid {
namespace DataObjects {
using Mantid::Kernel::Mutex;
//----------------------------------------------------------------------------------------------
/** Constructor
*/
......@@ -41,7 +39,7 @@ EventWorkspaceMRU::~EventWorkspaceMRU() {
* @param thread_num :: thread number that wants a MRU buffer
*/
void EventWorkspaceMRU::ensureEnoughBuffersE(size_t thread_num) const {
Mutex::ScopedLock _lock(m_changeMruListsMutexE);
Mantid::Kernel::LockGuardMutex _lock(m_changeMruListsMutexE);
if (m_bufferedDataE.size() <= thread_num) {
m_bufferedDataE.resize(thread_num + 1, nullptr);
for (auto &data : m_bufferedDataE) {
......@@ -56,7 +54,7 @@ void EventWorkspaceMRU::ensureEnoughBuffersE(size_t thread_num) const {
* @param thread_num :: thread number that wants a MRU buffer
*/
void EventWorkspaceMRU::ensureEnoughBuffersY(size_t thread_num) const {
Mutex::ScopedLock _lock(m_changeMruListsMutexY);
Mantid::Kernel::LockGuardMutex _lock(m_changeMruListsMutexY);
if (m_bufferedDataY.size() <= thread_num) {
m_bufferedDataY.resize(thread_num + 1, nullptr);
for (auto &data : m_bufferedDataY) {
......@@ -69,7 +67,7 @@ void EventWorkspaceMRU::ensureEnoughBuffersY(size_t thread_num) const {
//---------------------------------------------------------------------------
/// Clear all the data in the MRU buffers
void EventWorkspaceMRU::clear() {
Mutex::ScopedLock _lock(this->m_toDeleteMutex);
Mantid::Kernel::LockGuardMutex _lock(this->m_toDeleteMutex);
// FIXME: don't clear the locked ones!
for (auto &marker : m_markersToDelete)
......@@ -98,7 +96,7 @@ void EventWorkspaceMRU::clear() {
*found.
*/
MantidVecWithMarker *EventWorkspaceMRU::findY(size_t thread_num, size_t index) {
Mutex::ScopedLock _lock(m_changeMruListsMutexY);
Mantid::Kernel::LockGuardMutex _lock(m_changeMruListsMutexY);
return m_bufferedDataY[thread_num]->find(index);
}
......@@ -110,7 +108,7 @@ MantidVecWithMarker *EventWorkspaceMRU::findY(size_t thread_num, size_t index) {
*found.
*/
MantidVecWithMarker *EventWorkspaceMRU::findE(size_t thread_num, size_t index) {
Mutex::ScopedLock _lock(m_changeMruListsMutexE);
Mantid::Kernel::LockGuardMutex _lock(m_changeMruListsMutexE);
return m_bufferedDataE[thread_num]->find(index);
}
......@@ -122,12 +120,12 @@ MantidVecWithMarker *EventWorkspaceMRU::findE(size_t thread_num, size_t index) {
*needs to be deleted.
*/
void EventWorkspaceMRU::insertY(size_t thread_num, MantidVecWithMarker *data) {
Mutex::ScopedLock _lock(m_changeMruListsMutexY);
Mantid::Kernel::LockGuardMutex _lock(m_changeMruListsMutexY);
MantidVecWithMarker *oldData = m_bufferedDataY[thread_num]->insert(data);
// And clear up the memory of the old one, if it is dropping out.
if (oldData) {
if (oldData->m_locked) {
Mutex::ScopedLock _lock(this->m_toDeleteMutex);
Mantid::Kernel::LockGuardMutex _lock(this->m_toDeleteMutex);
m_markersToDelete.push_back(oldData);
} else
delete oldData;
......@@ -142,12 +140,12 @@ void EventWorkspaceMRU::insertY(size_t thread_num, MantidVecWithMarker *data) {
*needs to be deleted.
*/
void EventWorkspaceMRU::insertE(size_t thread_num, MantidVecWithMarker *data) {
Mutex::ScopedLock _lock(m_changeMruListsMutexE);
Mantid::Kernel::LockGuardMutex _lock(m_changeMruListsMutexE);
MantidVecWithMarker *oldData = m_bufferedDataE[thread_num]->insert(data);
// And clear up the memory of the old one, if it is dropping out.
if (oldData) {
if (oldData->m_locked) {
Mutex::ScopedLock _lock(this->m_toDeleteMutex);
Mantid::Kernel::LockGuardMutex _lock(this->m_toDeleteMutex);
m_markersToDelete.push_back(oldData);
} else
delete oldData;
......@@ -159,11 +157,11 @@ void EventWorkspaceMRU::insertE(size_t thread_num, MantidVecWithMarker *data) {
* @param index :: index to delete.
*/
void EventWorkspaceMRU::deleteIndex(size_t index) {
Mutex::ScopedLock _lock1(m_changeMruListsMutexE);
Mantid::Kernel::LockGuardMutex _lock1(m_changeMruListsMutexE);
for (auto &data : m_bufferedDataE)
if (data)
data->deleteIndex(index);
Mutex::ScopedLock _lock2(m_changeMruListsMutexY);
Mantid::Kernel::LockGuardMutex _lock2(m_changeMruListsMutexY);
for (auto &data : m_bufferedDataY)
if (data)
data->deleteIndex(index);
......
......@@ -4,8 +4,6 @@
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/Exception.h"
#include <Poco/Mutex.h>
#include <boost/variant/get.hpp>
using namespace Mantid::Kernel;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment