Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
Thread.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_THREADS_THREAD_HPP_
2#define IV_SRC_THREADS_THREAD_HPP_
3
5
6#include <csignal>
7#include <memory>
8#include <thread>
9
10namespace iv::threads
11{
12
13class Thread
14{
15public:
16 Thread() = delete;
17 explicit Thread(iv::threads::IRunnable **runnable, std::string_view threadName = "");
18 Thread(const Thread &other) = delete;
19 Thread(Thread &&other) = delete;
20 ~Thread();
21
22 Thread operator=(const Thread &other) = delete;
23 Thread operator=(Thread &&other) = delete;
24
25 [[nodiscard]] bool isRunning() const;
26 [[nodiscard]] bool isPaused() const;
27 [[nodiscard]] bool isStopped() const;
28
29 std::thread::id getId();
30 void startThread();
31 void pauseThread() const;
32 void resumeThread() const;
33 void waitingForFinished();
34
35private:
36 static void sigsegvHandler(int signo, siginfo_t *info, void *context);
37
38 enum class eThreadState
39 {
40 Init,
41 Running,
43 Stopped,
44 };
45
46 void prvRunThread() const;
47
48 std::unique_ptr<std::thread> m_handleThread;
51 std::string m_threadName;
52 std::atomic<bool> m_hasCrashed;
53};
54
55}// namespace iv::threads
56
57#endif /* IV_SRC_THREADS_THREAD_HPP_ */
Definition IRunnable.hpp:10
Definition Thread.hpp:14
eThreadState m_state
Definition Thread.hpp:50
std::atomic< bool > m_hasCrashed
Definition Thread.hpp:52
std::string m_threadName
Definition Thread.hpp:51
void prvRunThread() const
Definition Thread.cpp:119
Thread(Thread &&other)=delete
void resumeThread() const
Definition Thread.cpp:84
Thread(const Thread &other)=delete
Thread operator=(Thread &&other)=delete
Thread operator=(const Thread &other)=delete
void waitingForFinished()
Definition Thread.cpp:91
std::unique_ptr< std::thread > m_handleThread
Definition Thread.hpp:48
bool isRunning() const
Definition Thread.cpp:32
eThreadState
Definition Thread.hpp:39
~Thread()
Definition Thread.cpp:24
void pauseThread() const
Definition Thread.cpp:77
iv::threads::IRunnable * m_runnable
Definition Thread.hpp:49
std::thread::id getId()
Definition Thread.cpp:161
bool isStopped() const
Definition Thread.cpp:42
bool isPaused() const
Definition Thread.cpp:37
static void sigsegvHandler(int signo, siginfo_t *info, void *context)
Definition Thread.cpp:126
void startThread()
Definition Thread.cpp:47
Definition BackgroundTaskWithDialog.cpp:8