Core Library  1.6.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
IoServiceThreadGroup.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 IOSERVICETHREADGROUP
28 #define IOSERVICETHREADGROUP
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 IoServiceThreadGroup final
49 {
50 public:
58  explicit IoServiceThreadGroup(unsigned int numThreads = std::thread::hardware_concurrency());
62  IoServiceThreadGroup& operator=(const IoServiceThreadGroup&) = delete;
66  IoServiceThreadGroup& operator=(IoServiceThreadGroup&&) = delete;
73  boost_ioservice_t& IoService();
78  template <typename F> void Post(F function)
79  {
80  m_ioService.post(function);
81  }
82 
83 private:
87  boost_ioservice_t::work m_ioWork;
90 };
91 
92 } // namespace asio
93 } // namespace core_lib
94 
95 #endif // #define IOSERVICETHREADGROUP
core_lib::asio::IoServiceThreadGroup
I/O Service Thread group class.
Definition: IoServiceThreadGroup.h:48
core_lib::threads::ThreadGroup
Thread group class.
Definition: ThreadGroup.h:54
core_lib::asio::IoServiceThreadGroup::m_threadGroup
threads::ThreadGroup m_threadGroup
Our thread group.
Definition: IoServiceThreadGroup.h:89
ThreadGroup.h
File containing thread group declaration.
core_lib
The core_lib namespace.
Definition: AsioDefines.h:59
AsioDefines.h
File containing useful definitions.
core_lib::asio::IoServiceThreadGroup::m_ioService
boost_ioservice_t m_ioService
Boost ASIO I/O service.
Definition: IoServiceThreadGroup.h:85
core_lib::asio::IoServiceThreadGroup::Post
void Post(F function)
Post a function object to be run by one of our threads.
Definition: IoServiceThreadGroup.h:78
boost_ioservice_t
boost_asio::io_service boost_ioservice_t
Boost IO service convenience typedef.
Definition: AsioDefines.h:46
core_lib::asio::IoServiceThreadGroup::m_ioWork
boost_ioservice_t::work m_ioWork
Boost ASIO I/O service work object.
Definition: IoServiceThreadGroup.h:87