Newer
Older
Janik Zikovsky
committed
#include "MantidDataObjects/EventWorkspaceMRU.h"
#include "MantidKernel/System.h"
namespace Mantid {
namespace DataObjects {
using Mantid::Kernel::Mutex;
//----------------------------------------------------------------------------------------------
/** Constructor
*/
EventWorkspaceMRU::EventWorkspaceMRU() {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
EventWorkspaceMRU::~EventWorkspaceMRU() {
// Make sure you free up the memory in the MRUs
for (auto &data : m_bufferedDataY) {
if (data) {
data->clear();
delete data;
for (auto &data : m_bufferedDataE) {
if (data) {
data->clear();
delete data;
for (auto &marker : m_markersToDelete) {
delete marker;
Janik Zikovsky
committed
}
}
//---------------------------------------------------------------------------
/** This function makes sure that there are enough data
* buffers (MRU's) for E for the number of threads requested.
* @param thread_num :: thread number that wants a MRU buffer
*/
void EventWorkspaceMRU::ensureEnoughBuffersE(size_t thread_num) const {
Mutex::ScopedLock _lock(m_changeMruListsMutexE);
if (m_bufferedDataE.size() <= thread_num) {
m_bufferedDataE.resize(thread_num + 1, nullptr);
for (auto &data : m_bufferedDataE) {
if (!data)
data = new mru_list(50); // Create a MRU list with this many entries.
}
//---------------------------------------------------------------------------
/** This function makes sure that there are enough data
* buffers (MRU's) for Y for the number of threads requested.
* @param thread_num :: thread number that wants a MRU buffer
*/
void EventWorkspaceMRU::ensureEnoughBuffersY(size_t thread_num) const {
Mutex::ScopedLock _lock(m_changeMruListsMutexY);
if (m_bufferedDataY.size() <= thread_num) {
m_bufferedDataY.resize(thread_num + 1, nullptr);
for (auto &data : m_bufferedDataY) {
if (!data)
data = new mru_list(50); // Create a MRU list with this many entries.
Janik Zikovsky
committed
//---------------------------------------------------------------------------
/// Clear all the data in the MRU buffers
void EventWorkspaceMRU::clear() {
Mutex::ScopedLock _lock(this->m_toDeleteMutex);
Janik Zikovsky
committed
// FIXME: don't clear the locked ones!
for (auto &marker : m_markersToDelete)
if (!marker->m_locked)
delete marker;
Janik Zikovsky
committed
// Make sure you free up the memory in the MRUs
for (auto &data : m_bufferedDataY)
if (data) {
data->clear();
Janik Zikovsky
committed
for (auto &data : m_bufferedDataE)
if (data) {
data->clear();
Janik Zikovsky
committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//---------------------------------------------------------------------------
/** Find a Y histogram in the MRU
*
* @param thread_num :: number of the thread in which this is run
* @param index :: index of the data to return
* @return pointer to the MantidVecWithMarker that has the data; NULL if not
*found.
*/
MantidVecWithMarker *EventWorkspaceMRU::findY(size_t thread_num, size_t index) {
Mutex::ScopedLock _lock(m_changeMruListsMutexY);
return m_bufferedDataY[thread_num]->find(index);
}
/** Find a Y histogram in the MRU
*
* @param thread_num :: number of the thread in which this is run
* @param index :: index of the data to return
* @return pointer to the MantidVecWithMarker that has the data; NULL if not
*found.
*/
MantidVecWithMarker *EventWorkspaceMRU::findE(size_t thread_num, size_t index) {
Mutex::ScopedLock _lock(m_changeMruListsMutexE);
return m_bufferedDataE[thread_num]->find(index);
}
/** Insert a new histogram into the MRU
*
* @param thread_num :: thread being accessed
* @param data :: the new data
* @return a MantidVecWithMarker * that needs to be deleted, or NULL if nothing
*needs to be deleted.
*/
void EventWorkspaceMRU::insertY(size_t thread_num, MantidVecWithMarker *data) {
Mutex::ScopedLock _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);
m_markersToDelete.push_back(oldData);
} else
delete oldData;
Janik Zikovsky
committed
}
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
}
/** Insert a new histogram into the MRU
*
* @param thread_num :: thread being accessed
* @param data :: the new data
* @return a MantidVecWithMarker * that needs to be deleted, or NULL if nothing
*needs to be deleted.
*/
void EventWorkspaceMRU::insertE(size_t thread_num, MantidVecWithMarker *data) {
Mutex::ScopedLock _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);
m_markersToDelete.push_back(oldData);
} else
delete oldData;
}
}
/** Delete any entries in the MRU at the given index
*
* @param index :: index to delete.
*/
void EventWorkspaceMRU::deleteIndex(size_t index) {
Mutex::ScopedLock _lock1(m_changeMruListsMutexE);
for (auto &data : m_bufferedDataE)
if (data)
data->deleteIndex(index);
Mutex::ScopedLock _lock2(m_changeMruListsMutexY);
for (auto &data : m_bufferedDataY)
if (data)
data->deleteIndex(index);
Janik Zikovsky
committed
} // namespace Mantid
} // namespace DataObjects