QXRD  0.11.16
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | Private Slots | Private Member Functions | Private Attributes | List of all members
QcepAllocator Class Reference

#include <qcepallocator.h>

Inheritance diagram for QcepAllocator:
Inheritance graph
[legend]
Collaboration diagram for QcepAllocator:
Collaboration graph
[legend]

Public Types

enum  AllocationStrategy { WaitTillAvailable, NullIfNotAvailable, AllocateFromReserve, AlwaysAllocate }
 
enum  { MegaBytes = 0x100000 }
 

Public Member Functions

 QcepAllocator (QcepSettingsSaverPtr saver)
 
virtual ~QcepAllocator ()
 
void readSettings (QSettings *settings, QString section)
 
void writeSettings (QSettings *settings, QString section)
 
int int16SizeMB (int width, int height)
 
int int32SizeMB (int width, int height)
 
int doubleSizeMB (int width, int height)
 
int maskSizeMB (int width, int height)
 
int integratedSizeMB (int nrows)
 
double allocatedMemoryMB ()
 
double maximumMemoryMB ()
 
double maximumMemory ()
 
void changedSizeMB (int newMB)
 
QMutex * mutex ()
 
- Public Member Functions inherited from QcepObject
 QcepObject (QString name, QcepObject *parent)
 
virtual ~QcepObject ()
 
QString get_Name () const
 
void set_Name (QString name)
 

Static Public Member Functions

static QcepInt16ImageDataPtr newInt16Image (AllocationStrategy strat, int width, int height, QcepObject *parent)
 
static QcepInt32ImageDataPtr newInt32Image (AllocationStrategy strat, int width, int height, QcepObject *parent)
 
static QcepDoubleImageDataPtr newDoubleImage (AllocationStrategy strat, int width, int height, QcepObject *parent)
 
static QcepMaskDataPtr newMask (AllocationStrategy strat, int width, int height, int def, QcepObject *parent)
 
static QcepIntegratedDataPtr newIntegratedData (AllocationStrategy strat, QcepDoubleImageDataPtr image, QcepObject *parent)
 
static QcepDoubleImageDataPtr newDoubleImage (QString name, int width, int height, QcepObject *parent)
 
static QcepIntegratedDataPtr newIntegratedData (QString name, int size, QcepObject *parent)
 
static void newDoubleImageAndIntegratedData (AllocationStrategy strat, int width, int height, QcepObject *parent, QcepDoubleImageDataPtr &img, QcepIntegratedDataPtr &integ)
 
static void allocate (int sz, int width, int height)
 
static void deallocate (int sz, int width, int height)
 
static void allocate (quint64 amt)
 
static void deallocate (quint64 amt)
 
static quint64 allocatedMemory ()
 
- Static Public Member Functions inherited from QcepObject
static int allocatedObjects ()
 
static int deletedObjects ()
 
static QSet< QcepObject * > allocatedObjectsSet ()
 
static QString addSlashes (QString str)
 

Protected Member Functions

void allocateBytes (quint64 amt)
 
void deallocateBytes (quint64 amt)
 

Properties

int max
 
int totalBufferSizeMB32
 
int totalBufferSizeMB64
 
int reserve
 
int allocated
 
- Properties inherited from QcepObject
QString name
 

Private Slots

void allocatorHeartbeat ()
 

Private Member Functions

int waitTillAvailable (AllocationStrategy strat, int sizeMB)
 

Private Attributes

QMutex m_Mutex
 
QTimer m_Timer
 
QAtomicInt m_AllocatedMemoryMB
 

Additional Inherited Members

- Public Slots inherited from QcepObject
virtual void printLine (QString line)
 
virtual void printMessage (QString msg, QDateTime dt=QDateTime::currentDateTime()) const
 
virtual void criticalMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
virtual void statusMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
virtual QString settingsScript ()
 
QString scriptValueLiteral (QVariant v)
 

Detailed Description

Definition at line 17 of file qcepallocator.h.

Member Enumeration Documentation

anonymous enum
Enumerator
MegaBytes 

Definition at line 89 of file qcepallocator.h.

89 { MegaBytes = 0x100000 };
Enumerator
WaitTillAvailable 
NullIfNotAvailable 
AllocateFromReserve 
AlwaysAllocate 

Definition at line 30 of file qcepallocator.h.

Constructor & Destructor Documentation

QcepAllocator::QcepAllocator ( QcepSettingsSaverPtr  saver)

Definition at line 15 of file qcepallocator.cpp.

References allocatorHeartbeat(), DEBUG_ALLOCATOR, DEBUG_CONSTRUCTORS, g_Application, HEXARG, m_Timer, QcepApplication::printMessage(), and qcepDebug().

16  : QcepObject("allocator", NULL),
17  m_Mutex(QMutex::Recursive),
19  m_Max(saver, this, "max", 800, "Maximum Image Memory (MB)"),
20  m_TotalBufferSizeMB32(saver, this,"totalBufferSizeMB32", 800, "Maximum Image Memory in 32 bit system (MB)"),
21  m_TotalBufferSizeMB64(saver, this,"totalBufferSizeMB64", 2000,"Maximum Image Memory in 64 bit system (MB)"),
22  m_Reserve(saver, this,"reserve",100, "Extra Reserved Memory (MB)"),
23  m_Allocated(QcepSettingsSaverPtr(), this, "allocated", 0, "Allocated Memory (MB)")
24 {
25  if (g_Allocator) {
26  printf("Only one allocator can be created\n");
27  } else {
28  g_Allocator = this;
29  }
30 
32  printf("QcepAllocator::QcepAllocator(%p)\n", this);
33  }
34 
36  g_Application->printMessage(tr("allocator %1 constructed").HEXARG(this));
37  };
38 
39  connect(&m_Timer, SIGNAL(timeout()), this, SLOT(allocatorHeartbeat()));
40 
41  m_Timer.start(100);
42 
44 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static QcepAllocator * g_Allocator
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
QcepObject(QString name, QcepObject *parent)
Definition: qcepobject.cpp:16
#define HEXARG(a)
Definition: qcepdebug.h:50
QAtomicInt m_AllocatedMemoryMB
Definition: qcepallocator.h:86
void allocatorHeartbeat()
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application

Here is the call graph for this function:

QcepAllocator::~QcepAllocator ( )
virtual

Definition at line 46 of file qcepallocator.cpp.

References DEBUG_ALLOCATOR, DEBUG_CONSTRUCTORS, g_Application, HEXARG, QcepApplication::printMessage(), and qcepDebug().

47 {
48 #ifndef QT_NO_DEBUG
49  printf("Deleting allocator\n");
50 #endif
51 
52  g_Allocator = NULL;
53 
55  printf("QcepAllocator::~QcepAllocator(%p)\n", this);
56  }
57 
59  g_Application->printMessage(tr("allocator %1 deleted").HEXARG(this));
60  };
61 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static QcepAllocator * g_Allocator
#define HEXARG(a)
Definition: qcepdebug.h:50
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application

Here is the call graph for this function:

Member Function Documentation

void QcepAllocator::allocate ( int  sz,
int  width,
int  height 
)
static

Definition at line 308 of file qcepallocator.cpp.

Referenced by QcepDataArray::QcepDataArray(), QcepDataColumn::QcepDataColumn(), QcepImageDataBase::QcepImageDataBase(), QcepIntegratedData::QcepIntegratedData(), QcepIntegratedData::resize(), QcepDataColumn::resize(), and QcepImageData< T >::resize().

309 {
310  if (g_Allocator) {
311  g_Allocator -> allocate((quint64) sz*width*height);
312  }
313 }
static QcepAllocator * g_Allocator
static void allocate(int sz, int width, int height)

Here is the caller graph for this function:

void QcepAllocator::allocate ( quint64  amt)
static

Definition at line 316 of file qcepallocator.cpp.

References allocateBytes().

317 {
318  if (g_Allocator) {
319  g_Allocator -> allocateBytes(amt);
320  }
321 }
static QcepAllocator * g_Allocator
void allocateBytes(quint64 amt)

Here is the call graph for this function:

void QcepAllocator::allocateBytes ( quint64  amt)
protected

Definition at line 323 of file qcepallocator.cpp.

References g_AllocatedMemory, m_AllocatedMemoryMB, m_Mutex, and MegaBytes.

Referenced by allocate().

324 {
325  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
326 
327  g_AllocatedMemory += amt;
328 
329  m_AllocatedMemoryMB.fetchAndStoreOrdered(g_AllocatedMemory/MegaBytes);
330 }
QAtomicInt m_AllocatedMemoryMB
Definition: qcepallocator.h:86
static quint64 g_AllocatedMemory

Here is the caller graph for this function:

quint64 QcepAllocator::allocatedMemory ( )
static

Definition at line 392 of file qcepallocator.cpp.

References g_AllocatedMemory.

Referenced by main().

393 {
394  return g_AllocatedMemory;
395 }
static quint64 g_AllocatedMemory

Here is the caller graph for this function:

double QcepAllocator::allocatedMemoryMB ( )

Definition at line 387 of file qcepallocator.cpp.

References m_AllocatedMemoryMB.

Referenced by newDoubleImage(), newDoubleImageAndIntegratedData(), newInt16Image(), newInt32Image(), newIntegratedData(), and newMask().

388 {
389  return m_AllocatedMemoryMB.fetchAndAddOrdered(0);
390 }
QAtomicInt m_AllocatedMemoryMB
Definition: qcepallocator.h:86

Here is the caller graph for this function:

void QcepAllocator::allocatorHeartbeat ( )
privateslot

Definition at line 382 of file qcepallocator.cpp.

References m_AllocatedMemoryMB.

Referenced by QcepAllocator().

383 {
384  set_Allocated(m_AllocatedMemoryMB.fetchAndAddOrdered(0));
385 }
QAtomicInt m_AllocatedMemoryMB
Definition: qcepallocator.h:86

Here is the caller graph for this function:

void QcepAllocator::changedSizeMB ( int  newMB)

Definition at line 407 of file qcepallocator.cpp.

408 {
409  set_Max(newMB);
410 }
void QcepAllocator::deallocate ( int  sz,
int  width,
int  height 
)
static

Definition at line 333 of file qcepallocator.cpp.

Referenced by QcepDataArray::~QcepDataArray(), QcepDataColumn::~QcepDataColumn(), QcepImageDataBase::~QcepImageDataBase(), and QcepIntegratedData::~QcepIntegratedData().

334 {
335  if (g_Allocator) {
336  g_Allocator -> deallocate((quint64) sz*width*height);
337  }
338 }
static void deallocate(int sz, int width, int height)
static QcepAllocator * g_Allocator

Here is the caller graph for this function:

void QcepAllocator::deallocate ( quint64  amt)
static

Definition at line 341 of file qcepallocator.cpp.

References deallocateBytes().

342 {
343  if (g_Allocator) {
345  }
346 }
static QcepAllocator * g_Allocator
void deallocateBytes(quint64 amt)

Here is the call graph for this function:

void QcepAllocator::deallocateBytes ( quint64  amt)
protected

Definition at line 348 of file qcepallocator.cpp.

References g_AllocatedMemory, m_AllocatedMemoryMB, m_Mutex, and MegaBytes.

Referenced by deallocate().

349 {
350  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
351 
352  g_AllocatedMemory -= amt;
353 
354  m_AllocatedMemoryMB.fetchAndStoreOrdered(g_AllocatedMemory/MegaBytes);
355 }
QAtomicInt m_AllocatedMemoryMB
Definition: qcepallocator.h:86
static quint64 g_AllocatedMemory

Here is the caller graph for this function:

int QcepAllocator::doubleSizeMB ( int  width,
int  height 
)

Definition at line 367 of file qcepallocator.cpp.

References MegaBytes.

Referenced by newDoubleImage(), and newDoubleImageAndIntegratedData().

368 {
369  return sizeof(double)*width*height/MegaBytes;
370 }

Here is the caller graph for this function:

int QcepAllocator::int16SizeMB ( int  width,
int  height 
)

Definition at line 357 of file qcepallocator.cpp.

References MegaBytes.

Referenced by newInt16Image().

358 {
359  return sizeof(quint16)*width*height/MegaBytes;
360 }

Here is the caller graph for this function:

int QcepAllocator::int32SizeMB ( int  width,
int  height 
)

Definition at line 362 of file qcepallocator.cpp.

References MegaBytes.

Referenced by newInt32Image().

363 {
364  return sizeof(quint32)*width*height/MegaBytes;
365 }

Here is the caller graph for this function:

int QcepAllocator::integratedSizeMB ( int  nrows)

Definition at line 377 of file qcepallocator.cpp.

References MegaBytes.

Referenced by newDoubleImageAndIntegratedData(), and newIntegratedData().

378 {
379  return (sizeof(double)*4*nrows)/MegaBytes;
380 }

Here is the caller graph for this function:

int QcepAllocator::maskSizeMB ( int  width,
int  height 
)

Definition at line 372 of file qcepallocator.cpp.

References MegaBytes.

Referenced by newMask().

373 {
374  return sizeof(quint16)*width*height/MegaBytes;
375 }

Here is the caller graph for this function:

double QcepAllocator::maximumMemory ( )

Definition at line 402 of file qcepallocator.cpp.

References MegaBytes.

403 {
404  return get_Max()*MegaBytes;
405 }
double QcepAllocator::maximumMemoryMB ( )

Definition at line 397 of file qcepallocator.cpp.

398 {
399  return get_Max();
400 }
QMutex * QcepAllocator::mutex ( )

Definition at line 85 of file qcepallocator.cpp.

References m_Mutex.

Referenced by newDoubleImage(), newDoubleImageAndIntegratedData(), newInt16Image(), newInt32Image(), newIntegratedData(), and newMask().

86 {
87  return &m_Mutex;
88 }

Here is the caller graph for this function:

QcepDoubleImageDataPtr QcepAllocator::newDoubleImage ( AllocationStrategy  strat,
int  width,
int  height,
QcepObject parent 
)
static

Definition at line 169 of file qcepallocator.cpp.

References allocatedMemoryMB(), DEBUG_ALLOCATOR, doubleSizeMB(), g_Application, HEXARG, mutex(), QcepApplication::printMessage(), qcepDebug(), and waitTillAvailable().

Referenced by QxrdDetectorProcessor::doDarkSubtraction(), QxrdGenerateTestImage::generateChiImage(), QxrdGenerateTestImage::generateTTHImage(), newDoubleImage(), QxrdDetectorProcessor::onBadPixelsPathChanged(), QxrdIntegratorCache::performIntegration(), and QxrdDataProcessorBase::takeNextFreeImage().

170 {
171  if (g_Allocator) {
172  QcepMutexLocker lock(__FILE__, __LINE__, g_Allocator->mutex());
173 
174  if (g_Allocator->waitTillAvailable(strat, g_Allocator->doubleSizeMB(width, height))) {
175  QcepDoubleImageDataPtr res(new QcepDoubleImageData(QcepSettingsSaverPtr(), width, height, 0, parent));
176 
177  res -> moveToThread(NULL);
178 
180  g_Application->printMessage(tr("QcepAllocator::newDoubleImage() succeeded [%1] [%2]").HEXARG(res.data()).arg(g_Allocator->allocatedMemoryMB()));
181  }
182 
183  return res;
184  }
185  }
186 
188  g_Application->printMessage("QcepAllocator::newDoubleImage() returned NULL");
189  }
190 
191  return QcepDoubleImageDataPtr(NULL);
192 }
QcepImageData< double > QcepDoubleImageData
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static QcepAllocator * g_Allocator
int doubleSizeMB(int width, int height)
QMutex * mutex()
double allocatedMemoryMB()
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
#define HEXARG(a)
Definition: qcepdebug.h:50
int waitTillAvailable(AllocationStrategy strat, int sizeMB)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr

Here is the call graph for this function:

Here is the caller graph for this function:

QcepDoubleImageDataPtr QcepAllocator::newDoubleImage ( QString  name,
int  width,
int  height,
QcepObject parent 
)
static

Definition at line 194 of file qcepallocator.cpp.

References g_Application, newDoubleImage(), and NullIfNotAvailable.

195 {
197 
198  if (g_Application) {
199  img = newDoubleImage(QcepAllocator::NullIfNotAvailable, width, height, parent);
200 
201  if (img) {
202  img->set_Name(name);
203  img->moveToThread(NULL);
204  }
205  }
206 
207  return img;
208 }
static QcepDoubleImageDataPtr newDoubleImage(AllocationStrategy strat, int width, int height, QcepObject *parent)
QcepApplication * g_Application
QString name
Definition: qcepobject.h:49
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr

Here is the call graph for this function:

void QcepAllocator::newDoubleImageAndIntegratedData ( QcepAllocator::AllocationStrategy  strat,
int  width,
int  height,
QcepObject parent,
QcepDoubleImageDataPtr img,
QcepIntegratedDataPtr integ 
)
static

Definition at line 281 of file qcepallocator.cpp.

References allocatedMemoryMB(), DEBUG_ALLOCATOR, doubleSizeMB(), g_Application, HEXARG, integratedSizeMB(), mutex(), QcepApplication::printMessage(), qcepDebug(), and waitTillAvailable().

Referenced by QxrdDataProcessorThreaded::integrateData().

284 {
285  if (g_Allocator) {
286  QcepMutexLocker lock(__FILE__, __LINE__, g_Allocator->mutex());
287 
288  if (g_Allocator->waitTillAvailable(strat, g_Allocator->doubleSizeMB(width, height) + g_Allocator->integratedSizeMB(10000))) {
289  img = QcepDoubleImageDataPtr(new QcepDoubleImageData(QcepSettingsSaverPtr(), width, height, 0, parent));
290  integ = QcepIntegratedDataPtr(new QcepIntegratedData(QcepSettingsSaverPtr(), "", img, 10000, parent));
291 
292  img->moveToThread(NULL);
293  integ->moveToThread(NULL);
294 
296  g_Application->printMessage(tr("QcepAllocator::newDoubleImageAndIntegratedData() succeeded [%1] [%2] [%3]")
297  .HEXARG(img.data()).HEXARG(integ.data()).arg(g_Allocator->allocatedMemoryMB()));
298  }
299  }
300  }
301 
303  g_Application->printMessage("QcepAllocator::newDoubleImageAndIntegratedData() returned NULL");
304  }
305 }
QcepImageData< double > QcepDoubleImageData
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
static QcepAllocator * g_Allocator
int doubleSizeMB(int width, int height)
QMutex * mutex()
double allocatedMemoryMB()
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
#define HEXARG(a)
Definition: qcepdebug.h:50
int waitTillAvailable(AllocationStrategy strat, int sizeMB)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
int integratedSizeMB(int nrows)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr

Here is the call graph for this function:

Here is the caller graph for this function:

QcepInt16ImageDataPtr QcepAllocator::newInt16Image ( AllocationStrategy  strat,
int  width,
int  height,
QcepObject parent 
)
static

Definition at line 119 of file qcepallocator.cpp.

References allocatedMemoryMB(), DEBUG_ALLOCATOR, g_Application, HEXARG, int16SizeMB(), mutex(), QcepApplication::printMessage(), qcepDebug(), and waitTillAvailable().

Referenced by QxrdDetectorPerkinElmer::onEndFrame(), and QxrdDetectorSimulated::onTimerTimeout().

120 {
121  if (g_Allocator) {
122  QcepMutexLocker lock(__FILE__, __LINE__, g_Allocator->mutex());
123 
124  if (g_Allocator->waitTillAvailable(strat, g_Allocator->int16SizeMB(width, height))) {
125  QcepInt16ImageDataPtr res(new QcepInt16ImageData(QcepSettingsSaverPtr(), width, height, 0, parent));
126 
127  res->moveToThread(NULL);
128 
130  g_Application->printMessage(tr("QcepAllocator::newInt16Image() succeeded [%1] [%2]").HEXARG(res.data()).arg(g_Allocator->allocatedMemoryMB()));
131  }
132 
133  return res;
134  }
135  }
136 
138  g_Application->printMessage("QcepAllocator::newInt16Image() returned NULL");
139  }
140 
141  return QcepInt16ImageDataPtr(NULL);
142 }
QcepImageData< quint16 > QcepInt16ImageData
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
int int16SizeMB(int width, int height)
static QcepAllocator * g_Allocator
QMutex * mutex()
double allocatedMemoryMB()
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
#define HEXARG(a)
Definition: qcepdebug.h:50
int waitTillAvailable(AllocationStrategy strat, int sizeMB)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
QSharedPointer< QcepInt16ImageData > QcepInt16ImageDataPtr

Here is the call graph for this function:

Here is the caller graph for this function:

QcepInt32ImageDataPtr QcepAllocator::newInt32Image ( AllocationStrategy  strat,
int  width,
int  height,
QcepObject parent 
)
static

Definition at line 144 of file qcepallocator.cpp.

References allocatedMemoryMB(), DEBUG_ALLOCATOR, g_Application, HEXARG, int32SizeMB(), mutex(), QcepApplication::printMessage(), qcepDebug(), and waitTillAvailable().

Referenced by QxrdAcquisition::doAcquire(), QxrdAcquisition::doAcquireDark(), QxrdDetectorPilatus::loadAndPush(), QxrdDetectorProcessor::onDarkImagePathChanged(), and QxrdIntegratorCache::performIntegration().

145 {
146  if (g_Allocator) {
147  QcepMutexLocker lock(__FILE__, __LINE__, g_Allocator->mutex());
148 
149  if (g_Allocator->waitTillAvailable(strat, g_Allocator->int32SizeMB(width, height))) {
150  QcepInt32ImageDataPtr res(new QcepInt32ImageData(QcepSettingsSaverPtr(), width, height, 0, parent));
151 
152  res->moveToThread(NULL);
153 
155  g_Application->printMessage(tr("QcepAllocator::newInt32Image() succeeded [%1] [%2]").HEXARG(res.data()).arg(g_Allocator->allocatedMemoryMB()));
156  }
157 
158  return res;
159  }
160  }
161 
163  g_Application->printMessage("QcepAllocator::newInt32Image() returned NULL");
164  }
165 
166  return QcepInt32ImageDataPtr(NULL);
167 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
int int32SizeMB(int width, int height)
QcepImageData< quint32 > QcepInt32ImageData
static QcepAllocator * g_Allocator
QMutex * mutex()
double allocatedMemoryMB()
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
#define HEXARG(a)
Definition: qcepdebug.h:50
int waitTillAvailable(AllocationStrategy strat, int sizeMB)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QSharedPointer< QcepInt32ImageData > QcepInt32ImageDataPtr
QcepApplication * g_Application

Here is the call graph for this function:

Here is the caller graph for this function:

QcepIntegratedDataPtr QcepAllocator::newIntegratedData ( AllocationStrategy  strat,
QcepDoubleImageDataPtr  image,
QcepObject parent 
)
static

Definition at line 235 of file qcepallocator.cpp.

References allocatedMemoryMB(), DEBUG_ALLOCATOR, g_Application, HEXARG, integratedSizeMB(), mutex(), QcepApplication::printMessage(), qcepDebug(), and waitTillAvailable().

Referenced by QxrdDataProcessorThreaded::integrateSaveAndDisplay(), newIntegratedData(), QxrdDataProcessorBase::newOutputScan(), QxrdDataProcessorThreaded::onCorrectedImageAvailable(), QxrdIntegrator::performIntegration(), and QxrdDataProcessorThreaded::slicePolygon().

236 {
237  if (g_Allocator) {
238  QcepMutexLocker lock(__FILE__, __LINE__, g_Allocator->mutex());
239 
242  "",
243  data,
244  10000,
245  parent));
246 
247  res->moveToThread(NULL);
248 
250  g_Application->printMessage(tr("QcepAllocator::newIntegratedData() succeeded [%1] [%2]").HEXARG(res.data()).arg(g_Allocator->allocatedMemoryMB()));
251  }
252 
253  return res;
254  }
255  }
256 
258  g_Application->printMessage("QcepAllocator::newIntegratedData() returned NULL");
259  }
260 
261  return QcepIntegratedDataPtr(NULL);
262 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
static QcepAllocator * g_Allocator
QMutex * mutex()
double allocatedMemoryMB()
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
#define HEXARG(a)
Definition: qcepdebug.h:50
int waitTillAvailable(AllocationStrategy strat, int sizeMB)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
int integratedSizeMB(int nrows)

Here is the call graph for this function:

Here is the caller graph for this function:

QcepIntegratedDataPtr QcepAllocator::newIntegratedData ( QString  name,
int  size,
QcepObject parent 
)
static

Definition at line 264 of file qcepallocator.cpp.

References g_Application, newIntegratedData(), and NullIfNotAvailable.

265 {
266  QcepIntegratedDataPtr integ;
267 
268  if (g_Application) {
270 
271  if (integ) {
272  integ->set_Name(name);
273  integ->moveToThread(NULL);
274  integ->resize(size);
275  }
276  }
277 
278  return integ;
279 }
static QcepIntegratedDataPtr newIntegratedData(AllocationStrategy strat, QcepDoubleImageDataPtr image, QcepObject *parent)
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
QcepApplication * g_Application
QString name
Definition: qcepobject.h:49
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr

Here is the call graph for this function:

QcepMaskDataPtr QcepAllocator::newMask ( AllocationStrategy  strat,
int  width,
int  height,
int  def,
QcepObject parent 
)
static

Definition at line 210 of file qcepallocator.cpp.

References allocatedMemoryMB(), DEBUG_ALLOCATOR, g_Application, HEXARG, maskSizeMB(), mutex(), QcepApplication::printMessage(), qcepDebug(), and waitTillAvailable().

Referenced by QcepMaskData::copyMask(), QxrdAcquisition::doAcquire(), QxrdAcquisition::doAcquireDark(), QxrdDataProcessorBase::findZingers(), QxrdDataProcessorBase::loadMask(), QxrdDataProcessorBase::newMaskStack(), QxrdDetectorProcessor::onMaskPathChanged(), and QxrdDataProcessorBase::pushMaskStack().

211 {
212  if (g_Allocator) {
213  QcepMutexLocker lock(__FILE__, __LINE__, g_Allocator->mutex());
214 
215  if (g_Allocator->waitTillAvailable(strat, g_Allocator->maskSizeMB(width, height))) {
216  QcepMaskDataPtr res(new QcepMaskData(QcepSettingsSaverPtr(), width, height, def, parent));
217 
218  res->moveToThread(NULL);
219 
221  g_Application->printMessage(tr("QcepAllocator::newMask() succeeded [%1] [%2]").HEXARG(res.data()).arg(g_Allocator->allocatedMemoryMB()));
222  }
223 
224  return res;
225  }
226  }
227 
229  g_Application->printMessage("QcepAllocator::newMask() returned NULL");
230  }
231 
232  return QcepMaskDataPtr(NULL);
233 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static QcepAllocator * g_Allocator
int maskSizeMB(int width, int height)
QMutex * mutex()
double allocatedMemoryMB()
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
#define HEXARG(a)
Definition: qcepdebug.h:50
int waitTillAvailable(AllocationStrategy strat, int sizeMB)
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
QSharedPointer< QcepMaskData > QcepMaskDataPtr

Here is the call graph for this function:

Here is the caller graph for this function:

void QcepAllocator::readSettings ( QSettings *  settings,
QString  section 
)
virtual

Reimplemented from QcepObject.

Definition at line 70 of file qcepallocator.cpp.

References m_Mutex, MegaBytes, and QcepObject::readSettings().

71 {
72  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
73 
74  QcepObject::readSettings(settings, section);
75 
76  if (get_TotalBufferSizeMB32() > 100000000) {
77  set_TotalBufferSizeMB32(get_TotalBufferSizeMB32()/MegaBytes);
78  }
79 
80  if (get_TotalBufferSizeMB64() > 100000000) {
81  set_TotalBufferSizeMB64(get_TotalBufferSizeMB64()/MegaBytes);
82  }
83 }
virtual void readSettings(QSettings *set, QString section)
Definition: qcepobject.cpp:119

Here is the call graph for this function:

int QcepAllocator::waitTillAvailable ( AllocationStrategy  strat,
int  sizeMB 
)
private

Definition at line 90 of file qcepallocator.cpp.

References AllocateFromReserve, AlwaysAllocate, DEBUG_ALLOCATOR, g_Application, m_AllocatedMemoryMB, m_Mutex, QcepThread::msleep(), NullIfNotAvailable, QcepApplication::printMessage(), qcepDebug(), and WaitTillAvailable.

Referenced by newDoubleImage(), newDoubleImageAndIntegratedData(), newInt16Image(), newInt32Image(), newIntegratedData(), and newMask().

91 {
92  if (strat == QcepAllocator::WaitTillAvailable) {
93  while((m_AllocatedMemoryMB.fetchAndAddOrdered(0) + sizeMB) > get_Max()) {
94  m_Mutex.unlock();
95 
97  if (g_Application) {
98  g_Application->printMessage("QcepAllocator::waitTillAvailable() sleeping 100msec");
99  }
100  }
101 
102  QcepThread::msleep(100);
103 
104  m_Mutex.lock();
105  }
106 
107  return true;
108  } else if (strat == QcepAllocator::NullIfNotAvailable) {
109  return ((m_AllocatedMemoryMB.fetchAndAddOrdered(0) + sizeMB) < get_Max());
110  } else if (strat == QcepAllocator::AllocateFromReserve) {
111  return ((m_AllocatedMemoryMB.fetchAndAddOrdered(0) + sizeMB) < (get_Max() + get_Reserve()));
112  } else if (strat == QcepAllocator::AlwaysAllocate) {
113  return true;
114  } else {
115  return false;
116  }
117 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static void msleep(long unsigned int)
Definition: qcepthread.cpp:10
QAtomicInt m_AllocatedMemoryMB
Definition: qcepallocator.h:86
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application

Here is the call graph for this function:

Here is the caller graph for this function:

void QcepAllocator::writeSettings ( QSettings *  settings,
QString  section 
)
virtual

Reimplemented from QcepObject.

Definition at line 63 of file qcepallocator.cpp.

References m_Mutex, and QcepObject::writeSettings().

64 {
65  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
66 
67  QcepObject::writeSettings(settings, section);
68 }
virtual void writeSettings(QSettings *set, QString section)
Definition: qcepobject.cpp:114

Here is the call graph for this function:

Member Data Documentation

QAtomicInt QcepAllocator::m_AllocatedMemoryMB
private
QMutex QcepAllocator::m_Mutex
private
QTimer QcepAllocator::m_Timer
private

Definition at line 85 of file qcepallocator.h.

Referenced by QcepAllocator().

Property Documentation

int QcepAllocator::allocated
readwrite

Definition at line 103 of file qcepallocator.h.

int QcepAllocator::max
readwrite

Definition at line 91 of file qcepallocator.h.

int QcepAllocator::reserve
readwrite

Definition at line 100 of file qcepallocator.h.

int QcepAllocator::totalBufferSizeMB32
readwrite

Definition at line 94 of file qcepallocator.h.

int QcepAllocator::totalBufferSizeMB64
readwrite

Definition at line 97 of file qcepallocator.h.


The documentation for this class was generated from the following files: