unilink
0.4.3
A simple C++ library for unified async communication
io_context_manager.hpp
Go to the documentation of this file.
1
/*
2
* Copyright 2025 Jinwoo Sung
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
#pragma once
18
19
#include <boost/asio/executor_work_guard.hpp>
20
#include <boost/asio/io_context.hpp>
21
#include <memory>
22
23
#include "
unilink/base/visibility.hpp
"
24
25
namespace
unilink
{
26
namespace
concurrency {
27
32
class
UNILINK_API
IoContextManager
{
33
public
:
34
using
IoContext
= boost::asio::io_context;
35
using
WorkGuard
= boost::asio::executor_work_guard<IoContext::executor_type>;
36
37
static
IoContextManager
& instance();
38
39
IoContextManager
();
40
explicit
IoContextManager
(std::shared_ptr<IoContext> external_context);
41
explicit
IoContextManager
(
IoContext
& external_context);
42
~IoContextManager
();
43
44
// Move semantics
45
IoContextManager
(
IoContextManager
&&) noexcept;
46
IoContextManager
& operator=(
IoContextManager
&&) noexcept;
47
48
// Non-copyable
49
IoContextManager
(const
IoContextManager
&) = delete;
50
IoContextManager
& operator=(const
IoContextManager
&) = delete;
51
52
IoContext
& get_context();
53
void
start();
54
void
stop();
55
bool
is_running() const;
56
std::unique_ptr<
IoContext
> create_independent_context();
57
58
private:
59
struct
Impl
;
60
const
Impl
* get_impl()
const
{
return
impl_.get(); }
61
Impl* get_impl() {
return
impl_.get(); }
62
std::unique_ptr<Impl> impl_;
63
};
64
65
}
// namespace concurrency
66
67
namespace
common {
68
using
IoContextManager
=
concurrency::IoContextManager
;
69
}
// namespace common
70
}
// namespace unilink
unilink::concurrency::IoContextManager
Definition:
io_context_manager.hpp:32
unilink::concurrency::IoContextManager::IoContextManager
IoContextManager(IoContextManager &&) noexcept
unilink::concurrency::IoContextManager::WorkGuard
boost::asio::executor_work_guard< IoContext::executor_type > WorkGuard
Definition:
io_context_manager.hpp:35
unilink::concurrency::IoContextManager::~IoContextManager
~IoContextManager()
unilink::concurrency::IoContextManager::IoContext
boost::asio::io_context IoContext
Definition:
io_context_manager.hpp:34
unilink::common::IoContextManager
concurrency::IoContextManager IoContextManager
Definition:
io_context_manager.hpp:68
unilink
Definition:
common.hpp:37
unilink::concurrency::IoContextManager::Impl
Definition:
io_context_manager.cc:29
visibility.hpp
UNILINK_API
#define UNILINK_API
Definition:
visibility.hpp:37
unilink
concurrency
io_context_manager.hpp
Generated on Wed Mar 25 2026 21:38:57 for unilink by
1.9.1