Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
IoContextThreadGroup.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 IoContextThreadGroup_H
28 #define IoContextThreadGroup_H
29 
30 #include "Threads/ThreadGroup.h"
31 #include "AsioDefines.h"
32 
34 namespace core_lib
35 {
37 namespace asio
38 {
39 
48 class CORE_LIBRARY_DLL_SHARED_API IoContextThreadGroup final
49 {
50 public:
58  explicit IoContextThreadGroup(unsigned int numThreads = std::thread::hardware_concurrency());
62  IoContextThreadGroup& operator=(const IoContextThreadGroup&) = delete;
66  IoContextThreadGroup& operator=(IoContextThreadGroup&&) = delete;
73  boost_iocontext_t& IoContext();
78  template <typename F> void Post(F&& function)
79  {
80  boost_asio::post(m_ioContext, std::forward<F>(function));
81  }
82 
83 private:
87  boost::asio::executor_work_guard<boost::asio::io_context::executor_type> m_ioWorkGuard;
90 };
91 
92 } // namespace asio
93 } // namespace core_lib
94 
95 #endif // #define IoContextThreadGroup_H
void Post(F &&function)
Post a function object to be run by one of our threads.
Definition: IoContextThreadGroup.h:78
File containing useful definitions.
I/O Context Thread group class.
Definition: IoContextThreadGroup.h:48
The core_lib namespace.
Definition: AsioDefines.h:59
boost_iocontext_t m_ioContext
Boost ASIO I/O context.
Definition: IoContextThreadGroup.h:85
File containing thread group declaration.
Thread group class.
Definition: ThreadGroup.h:54
boost_asio::io_context boost_iocontext_t
Boost IO context convenience typedef.
Definition: AsioDefines.h:46
threads::ThreadGroup m_threadGroup
Our thread group.
Definition: IoContextThreadGroup.h:89
boost::asio::executor_work_guard< boost::asio::io_context::executor_type > m_ioWorkGuard
Boost ASIO I/O context work guard object.
Definition: IoContextThreadGroup.h:87