QXRD  0.11.16
qcepallocatorthread.cpp
Go to the documentation of this file.
1 #include "qcepdebug.h"
2 #include "qcepallocatorthread.h"
3 
4 #include "qcepallocator.h"
5 #include "qcepapplication.h"
6 #include "qcepmutexlocker.h"
7 #include <stdio.h>
8 
10  : QcepThread(),
11  m_Allocator(NULL),
12  m_Saver(saver)
13 {
15  printf("QcepAllocatorThread::QcepAllocatorThread(%p)\n", this);
16  }
17 }
18 
20 {
21  shutdown();
22 
24  printf("QcepAllocatorThread::~QcepAllocatorThread(%p)\n", this);
25  }
26 }
27 
29 {
30  if (qcepDebug(DEBUG_THREADS)) {
31  printf("Starting Allocator Thread\n");
32  }
33 
35 
36  int rc = -1;
37 
38  if (p) {
39  m_Mutex.lock();
40 
41  m_Allocator = p;
42 
43  m_Mutex.unlock();
44 
45  rc = exec();
46  }
47 
48  if (qcepDebug(DEBUG_THREADS)) {
49  printf("Allocator Thread Terminated with rc %d\n", rc);
50  }
51 
52  {
53  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
54 
56  }
57 }
58 
60 {
61  exit();
62 
63  wait();
64 }
65 
67 {
68 
69  while (isRunning()) {
70  {
71  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
72  if (m_Allocator) return m_Allocator;
73  }
74 
75  QThread::msleep(50);
76  }
77 
78  return QcepAllocatorPtr();
79 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QcepAllocatorThread(QcepSettingsSaverPtr saver)
QcepAllocatorPtr m_Allocator
QcepSettingsSaverPtr m_Saver
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
QMutex m_Mutex
Definition: qcepthread.h:17
QcepAllocatorPtr allocator() const
QSharedPointer< QcepAllocator > QcepAllocatorPtr