QXRD  0.11.16
qcepmutexlocker.cpp
Go to the documentation of this file.
1 #include "qcepmutexlocker.h"
2 #include <stdio.h>
3 #include <QThread>
4 #include "qcepdebug.h"
5 #include <QString>
6 #include <QObject>
7 
8 QcepMutexLocker::QcepMutexLocker(const char *file, int line, QMutex * mutex)
9  : QMutexLocker(mutex),
10  m_File(file),
11  m_Line(line)
12 {
13  if (qcepDebug(DEBUG_LOCKING)) {
14  m_LockTime.start();
15  traceLock(file, line);
16  }
17 }
18 
20 {
21  if (qcepDebug(DEBUG_LOCKING)) {
22  if (m_LockTime.elapsed() > 1000) {
23  printf("Lock held for %d msec, file %s, line %d, thread %p\n",
24  m_LockTime.elapsed(), m_File, m_Line, QThread::currentThread());
25  }
26  }
27 }
28 
29 QMap<QString,int> g_LockMap;
30 
31 void QcepMutexLocker::traceLock(const char *file, int line)
32 {
33  QString key = QString(file)+":"+QString::number(line);
34 
35  g_LockMap[key] += 1;
36 }
37 
39 {
40  QMapIterator<QString, int> i(g_LockMap);
41 
42  while (i.hasNext()) {
43  i.next();
44 
45  printf("Key: %s : Count %d\n", qPrintable(i.key()), i.value());
46  }
47 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static void traceLock(const char *file, int line)
static void dumpLocks()
QMap< QString, int > g_LockMap
QcepMutexLocker(const char *file, int line, QMutex *mutex)
const char * m_File