Core Library 1.7.0.0 Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.

ThreadRunner.h
Go to the documentation of this file.
1 // This file is part of CoreLibrary containing useful reusable utility
2 // classes.
3 //
4 // Copyright (C) 2014 to present, Duncan Crutchley
5 // Contact <dac1976github@outlook.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published
9 // by the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License and GNU Lesser General Public License
16 // for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // and GNU Lesser General Public License along with this program. If
20 // not, see <http://www.gnu.org/licenses/>.
21
27 #ifndef THREADRUNNER
28 #define THREADRUNNER
29
30 #include <functional>
31 #include "ThreadBase.h"
32
34 namespace core_lib
35 {
37 namespace threads
38 {
39
47 class CORE_LIBRARY_DLL_SHARED_API ThreadRunner final : public ThreadBase
48 {
50 using thread_function_t = std::function<void()>;
51
52 public:
54 ThreadRunner() = delete;
56 ThreadRunner(const ThreadRunner&) = delete;
58 ThreadRunner& operator=(const ThreadRunner&) = delete;
60 ThreadRunner(ThreadRunner&&) = delete;
62 ThreadRunner& operator=(ThreadRunner&&) = delete;
72 ThreadRunner(const thread_function_t& threadFunction,
73 const thread_function_t& processTerminationConditions, bool autoStart = false);
75 ~ThreadRunner() override;
84 void SleepThreadForTime(unsigned int milliSecs) const;
85
86 private:
88 thread_function_t m_threadFunction;
90 thread_function_t m_processTerminationConditions;
91
103 void ThreadIteration() NO_EXCEPT_ override;
113 void ProcessTerminationConditions() NO_EXCEPT_ override;
114 };
115
116 } // namespace threads
117 } // namespace core_lib
118
119 #endif // THREADRUNNER
core_lib::threads::ThreadRunner::m_processTerminationConditions
thread_function_t m_processTerminationConditions
Functor to call in the ProcessTerminationConditions method.
Definition: ThreadRunner.h:90
core_lib::threads::ThreadBase
Thread base class.
Definition: ThreadBase.h:49
ThreadBase.h
File containing declaration of ThreadBase class.
core_lib::threads::ThreadRunner
ThreadRunner class.
Definition: ThreadRunner.h:47
core_lib
The core_lib namespace.
Definition: AsioDefines.h:59
core_lib::threads::ThreadRunner::m_threadFunction
thread_function_t m_threadFunction
Functor to call in the ThreadFunction method.
Definition: ThreadRunner.h:88
core_lib::threads::ThreadRunner::thread_function_t
std::function< void()> thread_function_t
Typedef defining functor for virtual thread functions.
Definition: ThreadRunner.h:50
NO_EXCEPT_
#define NO_EXCEPT_
NO_EXCEPT_ definition mapping to noexcept.
Definition: PlatformDefines.h:57