]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/example/cpp03/http/server2/io_context_pool.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / asio / example / cpp03 / http / server2 / io_context_pool.hpp
CommitLineData
b32b8144
FG
1//
2// io_context_pool.hpp
3// ~~~~~~~~~~~~~~~~~~~
4//
92f5a8d4 5// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
b32b8144
FG
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9//
10
11#ifndef HTTP_SERVER2_IO_SERVICE_POOL_HPP
12#define HTTP_SERVER2_IO_SERVICE_POOL_HPP
13
14#include <boost/asio.hpp>
15#include <list>
16#include <vector>
17#include <boost/noncopyable.hpp>
18#include <boost/shared_ptr.hpp>
19
20namespace http {
21namespace server2 {
22
23/// A pool of io_context objects.
24class io_context_pool
25 : private boost::noncopyable
26{
27public:
28 /// Construct the io_context pool.
29 explicit io_context_pool(std::size_t pool_size);
30
31 /// Run all io_context objects in the pool.
32 void run();
33
34 /// Stop all io_context objects in the pool.
35 void stop();
36
37 /// Get an io_context to use.
38 boost::asio::io_context& get_io_context();
39
40private:
41 typedef boost::shared_ptr<boost::asio::io_context> io_context_ptr;
42 typedef boost::asio::executor_work_guard<
43 boost::asio::io_context::executor_type> io_context_work;
44
45 /// The pool of io_contexts.
46 std::vector<io_context_ptr> io_contexts_;
47
48 /// The work that keeps the io_contexts running.
49 std::list<io_context_work> work_;
50
51 /// The next io_context to use for a connection.
52 std::size_t next_io_context_;
53};
54
55} // namespace server2
56} // namespace http
57
58#endif // HTTP_SERVER2_IO_SERVICE_POOL_HPP