Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/DDS/FTC/generic_ftc_threading.h
T
berrux-dev 156c2dfcdc Restore legacy @RDE_HEADER@ comment blocks stripped by the Qt6 migration
The migration pipeline dropped the leading @RDE_HEADER@ comment blocks
from 243 target source files (and 2 cmake macros). Restore them
byte-for-byte from the legacy Qt5 tree
(qt5-before/qt5-legatus-legacy): the exact legacy header is re-inserted
at the top of each file (block-comment, '#'-style, line-comment '//'
styles, BOM and surrounding blank lines included). File bodies are
untouched.

Scope: all in-scope target code, unit-test directories excluded.
190 files already kept their legacy header through the migration and
were left as-is; legacy files without an RDE header were not given
one. Special cases: 3 headers sitting after a '#pragma once' line,
1 BOM-prefixed file, 4 '//'-style TetraIF headers. *.grantlee template
files were not in scope and remain untouched.

Verified: every restored file is byte-exact (legacy preamble + original
body) and the ctest baseline is unchanged (20/23 passed, 3 Not Run as
before).
2026-11-15 23:22:04 +01:00

99 lines
2.4 KiB
C++
Executable File

#pragma once
/**
* @RDE_HEADER@
* Thread management for generic FTCs
* $Id: generic_ftc_impl.h 62388 2024-03-27 10:41:26Z wille_m $
* $HeadURL: svn://slssvn/TDS/branches/product/features/swp_2023_devel/Lts/DDS/FTC/generic_ftc_impl.h $
* $Author: wille_m $
*
* Created by Mike Wille, ESZS, 27-03-2024
*/
#include <QtCore/QObject>
#include <QtCore/QAtomicInt>
#include <QtCore/QTimer>
#include <thread>
#include <exception>
#include <condition_variable>
class CancelationPointReached : public std::runtime_error
{
public:
explicit CancelationPointReached()
: std::runtime_error("CancelationPointReached")
{}
};
class Threading
{
public:
Threading() = default;
~Threading();
protected:
void preInit() const;
void createThread();
void runThread();
inline bool isRun() const { return (m_run != 0); }
inline void setRun(bool run) { m_run = (run ? 1 : 0); }
inline void setWorkAvailable(bool workAvailable) { m_workAvailable = (workAvailable ? 1 : 0); }
inline bool isWorkAvailable() const { return (m_workAvailable != 0); }
inline void setWorking(bool working) { m_isWorking = (working ? 1 : 0); }
inline bool isWorking() const { return (m_isWorking != 0); }
const QString &threadName() const;
inline const char *posixThreadName() const;
virtual void work() = 0;
virtual QString functionTopicName() const = 0;
virtual int partitionId() const = 0;
virtual QString partitionType() const = 0;
virtual void cleanupThread() = 0;
virtual void threadDone() = 0;
inline void cancellationPoint() const noexcept(false)
{
if (!isRun())
{
throw CancelationPointReached();
}
}
std::mutex m_conditionMutex;
private:
inline bool isCleanupNeeded() const { return (m_cleanupNeeded != 0); }
inline void setCleanupNeeded(bool cleanupNeeded) { m_cleanupNeeded = (cleanupNeeded ? 1 : 0); }
void run(const QString &threadName);
std::unique_ptr<QTimer> m_threadLifetime;
QAtomicInt m_run { 0 };
QAtomicInt m_cleanupNeeded { 1 };
std::thread m_thread;
std::condition_variable m_condition;
QAtomicInt m_workAvailable { 0 };
QAtomicInt m_isWorking { 0 };
mutable QString m_threadName;
mutable std::string m_posixThreadName;
QAtomicInt m_alreadyThreaded;
mutable int m_partitionId { -1 };
mutable QString m_partitionType;
bool m_used { false };
bool m_createThreadCalledBefore { false };
};