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:
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
thread_function_t m_processTerminationConditions
Functor to call in the ProcessTerminationConditions method.
Definition: ThreadRunner.h:90
Thread base class.
Definition: ThreadBase.h:49
File containing declaration of ThreadBase class.
ThreadRunner class.
Definition: ThreadRunner.h:47
The core_lib namespace.
Definition: AsioDefines.h:59
thread_function_t m_threadFunction
Functor to call in the ThreadFunction method.
Definition: ThreadRunner.h:88
std::function< void()> thread_function_t
Typedef defining functor for virtual thread functions.
Definition: ThreadRunner.h:50
#define NO_EXCEPT_
NO_EXCEPT_ definition mapping to noexcept.
Definition: PlatformDefines.h:57