system_executor.cpp
4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//
// system_executor.cpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Prevent link dependency on the Boost.System library.
#if !defined(BOOST_SYSTEM_NO_DEPRECATED)
#define BOOST_SYSTEM_NO_DEPRECATED
#endif // !defined(BOOST_SYSTEM_NO_DEPRECATED)
// Test that header file is self-contained.
#include "asio/system_executor.hpp"
#include "asio/dispatch.hpp"
#include "asio/post.hpp"
#include "unit_test.hpp"
#if defined(ASIO_HAS_BOOST_BIND)
# include <boost/bind/bind.hpp>
#else // defined(ASIO_HAS_BOOST_BIND)
# include <functional>
#endif // defined(ASIO_HAS_BOOST_BIND)
using namespace asio;
#if defined(ASIO_HAS_BOOST_BIND)
namespace bindns = boost;
#else // defined(ASIO_HAS_BOOST_BIND)
namespace bindns = std;
#endif
void increment(asio::detail::atomic_count* count)
{
++(*count);
}
void system_executor_query_test()
{
ASIO_CHECK(
&asio::query(system_executor(),
asio::execution::context)
!= static_cast<const system_context*>(0));
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::blocking)
== asio::execution::blocking.possibly);
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::blocking.possibly)
== asio::execution::blocking.possibly);
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::outstanding_work)
== asio::execution::outstanding_work.untracked);
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::outstanding_work.untracked)
== asio::execution::outstanding_work.untracked);
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::relationship)
== asio::execution::relationship.fork);
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::relationship.fork)
== asio::execution::relationship.fork);
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::bulk_guarantee)
== asio::execution::bulk_guarantee.unsequenced);
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::mapping)
== asio::execution::mapping.thread);
ASIO_CHECK(
asio::query(system_executor(),
asio::execution::allocator)
== std::allocator<void>());
}
void system_executor_execute_test()
{
asio::detail::atomic_count count(0);
asio::execution::execute(system_executor(),
bindns::bind(increment, &count));
asio::execution::execute(
asio::require(system_executor(),
asio::execution::blocking.possibly),
bindns::bind(increment, &count));
asio::execution::execute(
asio::require(system_executor(),
asio::execution::blocking.always),
bindns::bind(increment, &count));
asio::execution::execute(
asio::require(system_executor(),
asio::execution::blocking.never),
bindns::bind(increment, &count));
asio::execution::execute(
asio::require(system_executor(),
asio::execution::blocking.never,
asio::execution::outstanding_work.untracked),
bindns::bind(increment, &count));
asio::execution::execute(
asio::require(system_executor(),
asio::execution::blocking.never,
asio::execution::outstanding_work.untracked,
asio::execution::relationship.fork),
bindns::bind(increment, &count));
asio::execution::execute(
asio::require(system_executor(),
asio::execution::blocking.never,
asio::execution::outstanding_work.untracked,
asio::execution::relationship.continuation),
bindns::bind(increment, &count));
asio::execution::execute(
asio::prefer(
asio::require(system_executor(),
asio::execution::blocking.never,
asio::execution::outstanding_work.untracked,
asio::execution::relationship.continuation),
asio::execution::allocator(std::allocator<void>())),
bindns::bind(increment, &count));
asio::execution::execute(
asio::prefer(
asio::require(system_executor(),
asio::execution::blocking.never,
asio::execution::outstanding_work.untracked,
asio::execution::relationship.continuation),
asio::execution::allocator),
bindns::bind(increment, &count));
asio::query(system_executor(), execution::context).join();
ASIO_CHECK(count == 9);
}
ASIO_TEST_SUITE
(
"system_executor",
ASIO_TEST_CASE(system_executor_query_test)
ASIO_TEST_CASE(system_executor_execute_test)
)