swift
threadutils.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "misc/threadutils.h"
5 
6 #include <sstream>
7 #include <thread>
8 
9 #include <QCoreApplication>
10 #include <QObject>
11 #include <QThread>
12 #include <QtGlobal>
13 
14 namespace swift::misc
15 {
16  bool CThreadUtils::isInThisThread(const QObject *toBeTested)
17  {
18  return QThread::currentThread() == toBeTested->thread();
19  }
20 
21  bool CThreadUtils::thisIsMainThread() { return qApp && QThread::currentThread() == qApp->thread(); }
22 
24  {
25  std::ostringstream oss;
26  oss << std::this_thread::get_id();
27  const QThread *thread = QThread::currentThread();
28  const QString id = QString::fromStdString(oss.str());
29  return QStringLiteral("%1 (%2) prio %3").arg(id).arg(thread->objectName()).arg(thread->priority());
30  }
31 } // namespace swift::misc
static bool thisIsMainThread()
Is the current thread the application thread?
Definition: threadutils.cpp:21
static QString currentThreadInfo()
Info about current thread, for debug messages.
Definition: threadutils.cpp:23
static bool isInThisThread(const QObject *toBeTested)
Is the current thread the object's thread?
Definition: threadutils.cpp:16
Free functions in swift::misc.