From d3c3fe256624a46a2c448e6589f1142045f5f1ed Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 21 Aug 2018 15:12:06 +0200 Subject: [PATCH] Thread priority to string --- src/blackmisc/threadutils.cpp | 24 ++++++++++++++++++++++++ src/blackmisc/threadutils.h | 6 ++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/blackmisc/threadutils.cpp b/src/blackmisc/threadutils.cpp index 87005b28c..3b65d9919 100644 --- a/src/blackmisc/threadutils.cpp +++ b/src/blackmisc/threadutils.cpp @@ -37,4 +37,28 @@ namespace BlackMisc if (!QCoreApplication::instance()->thread()) { return false; } return (QCoreApplication::instance()->thread() == QThread::currentThread()); } + + const QString &CThreadUtils::priorityToString(QThread::Priority priority) + { + static const QString idle("idle"); + static const QString lowest("lowest"); + static const QString low("low"); + static const QString normal("normal"); + static const QString high("high"); + static const QString highest("highest"); + + switch (priority) + { + case QThread::IdlePriority: return idle; + case QThread::LowestPriority: return lowest; + case QThread::LowPriority: return low; + case QThread::NormalPriority: return normal; + case QThread::HighPriority: return high; + case QThread::HighestPriority: return highest; + default: break; + } + + static const QString unknown("unknown"); + return unknown; + } } // ns diff --git a/src/blackmisc/threadutils.h b/src/blackmisc/threadutils.h index 8da499228..30aa9bb04 100644 --- a/src/blackmisc/threadutils.h +++ b/src/blackmisc/threadutils.h @@ -13,8 +13,7 @@ #define BLACKMISC_CTHREADUTILS_H #include "blackmisc/blackmiscexport.h" - -class QObject; +#include namespace BlackMisc { @@ -38,6 +37,9 @@ namespace BlackMisc //! Is the current thread the Application thread? //! \remarks can be used as ASSERT check for threaded objects static bool isCurrentThreadApplicationThread(); + + //! Priority to string + static const QString &priorityToString(QThread::Priority priority); }; } // ns