Disable io_context::work when ASIO_NO_DEPRECATED is defined.

This commit is contained in:
Christopher Kohlhoff 2016-08-25 07:48:33 +10:00
parent cbcaf259cf
commit 87ecd843d3
12 changed files with 33 additions and 18 deletions

View File

@ -39,7 +39,7 @@ resolver_service_base::resolver_service_base(
work_io_context_(new asio::io_context),
work_io_context_impl_(asio::use_service<
io_context_impl>(*work_io_context_)),
work_(new asio::io_context::work(*work_io_context_)),
work_(asio::make_work_guard(*work_io_context_)),
work_thread_(0)
{
}

View File

@ -17,6 +17,7 @@
#include "asio/detail/config.hpp"
#include "asio/error.hpp"
#include "asio/executor_work_guard.hpp"
#include "asio/io_context.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/noncopyable.hpp"
@ -120,7 +121,8 @@ private:
io_context_impl& work_io_context_impl_;
// Work for the private io_context to perform.
asio::detail::scoped_ptr<asio::io_context::work> work_;
asio::executor_work_guard<
asio::io_context::executor_type> work_;
// Thread used for running the work io_context's run loop.
asio::detail::scoped_ptr<asio::detail::thread> work_thread_;

View File

@ -311,6 +311,7 @@ io_context::executor_type::running_in_this_thread() const ASIO_NOEXCEPT
return io_context_.impl_.can_dispatch();
}
#if !defined(ASIO_NO_DEPRECATED)
inline io_context::work::work(asio::io_context& io_context)
: io_context_impl_(io_context.impl_)
{
@ -333,7 +334,6 @@ inline asio::io_context& io_context::work::get_io_context()
return static_cast<asio::io_context&>(io_context_impl_.context());
}
#if !defined(ASIO_NO_DEPRECATED)
inline asio::io_context& io_context::work::get_io_service()
{
return static_cast<asio::io_context&>(io_context_impl_.context());

View File

@ -123,10 +123,12 @@ namespace detail {
* returning when there is no more work to do. For example, the io_context may
* be being run in a background thread that is launched prior to the
* application's asynchronous operations. The run() call may be kept running by
* creating an object of type asio::io_context::work:
* creating an object of type
* asio::executor_work_guard<io_context::executor_type>:
*
* @code asio::io_context io_context;
* asio::io_context::work work(io_context);
* asio::executor_work_guard<asio::io_context::executor_type>
* = asio::make_work_guard(io_context);
* ... @endcode
*
* To effect a shutdown, the application will then need to call the io_context
@ -135,11 +137,11 @@ namespace detail {
* permitting ready handlers to be dispatched.
*
* Alternatively, if the application requires that all operations and handlers
* be allowed to finish normally, the work object may be explicitly destroyed.
* be allowed to finish normally, the work object may be explicitly reset.
*
* @code asio::io_context io_context;
* auto_ptr<asio::io_context::work> work(
* new asio::io_context::work(io_context));
* asio::executor_work_guard<asio::io_context::executor_type>
* = asio::make_work_guard(io_context);
* ...
* work.reset(); // Allow run() to exit. @endcode
*/
@ -156,8 +158,10 @@ public:
class executor_type;
friend class executor_type;
#if !defined(ASIO_NO_DEPRECATED)
class work;
friend class work;
#endif // !defined(ASIO_NO_DEPRECATED)
class service;
@ -680,6 +684,7 @@ private:
io_context& io_context_;
};
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated: Use executor_work_guard.) Class to inform the io_context when
/// it has work to do.
/**
@ -734,6 +739,7 @@ private:
// The io_context implementation.
detail::io_context_impl& io_context_impl_;
};
#endif // !defined(ASIO_NO_DEPRECATED)
/// Base class for all io_context services.
class io_context::service

View File

@ -38,7 +38,7 @@
<member><link linkend="asio.reference.io_context__executor_type">io_context::executor_type</link></member>
<member><link linkend="asio.reference.io_context__service">io_context::service</link></member>
<member><link linkend="asio.reference.io_context__strand">io_context::strand</link></member>
<member><link linkend="asio.reference.io_context__work">io_context::work</link></member>
<member><link linkend="asio.reference.io_context__work">io_context::work</link> (deprecated)</member>
<member><link linkend="asio.reference.service_already_exists">service_already_exists</link></member>
<member><link linkend="asio.reference.system_error">system_error</link></member>
<member><link linkend="asio.reference.system_executor">system_executor</link></member>

View File

@ -27,7 +27,7 @@ io_context_pool::io_context_pool(std::size_t pool_size)
for (std::size_t i = 0; i < pool_size; ++i)
{
io_context_ptr io_context(new asio::io_context);
work_ptr work(new asio::io_context::work(*io_context));
work_ptr work(new io_context_work(asio::make_work_guard(*io_context)));
io_contexts_.push_back(io_context);
work_.push_back(work);
}

View File

@ -38,7 +38,9 @@ public:
private:
typedef boost::shared_ptr<asio::io_context> io_context_ptr;
typedef boost::shared_ptr<asio::io_context::work> work_ptr;
typedef asio::executor_work_guard<
asio::io_context::executor_type> io_context_work;
typedef boost::shared_ptr<io_context_work> work_ptr;
/// The pool of io_contexts.
std::vector<io_context_ptr> io_contexts_;

View File

@ -44,7 +44,7 @@ public:
logger_service(asio::io_context& io_context)
: asio::io_context::service(io_context),
work_io_context_(),
work_(new asio::io_context::work(work_io_context_)),
work_(asio::make_work_guard(work_io_context_)),
work_thread_(new asio::thread(
boost::bind(&asio::io_context::run, &work_io_context_)))
{
@ -130,7 +130,8 @@ private:
/// Work for the private io_context to perform. If we do not give the
/// io_context some work to do then the io_context::run() function will exit
/// immediately.
boost::scoped_ptr<asio::io_context::work> work_;
asio::executor_work_guard<
asio::io_context::executor_type> work_;
/// Thread used for running the work io_context's run loop.
boost::scoped_ptr<asio::thread> work_thread_;

View File

@ -77,7 +77,7 @@ int main(int argc, char* argv[])
// We run the io_context off in its own thread so that it operates
// completely asynchronously with respect to the rest of the program.
asio::io_context io_context;
asio::io_context::work work(io_context);
auto work = asio::make_work_guard(io_context);
std::thread thread([&io_context](){ io_context.run(); });
get_daytime(io_context, argv[1]);

View File

@ -22,6 +22,7 @@
#include <boost/bind.hpp>
#include "archetypes/async_result.hpp"
#include "asio/executor_work_guard.hpp"
#include "asio/io_context.hpp"
#include "asio/placeholders.hpp"
#include "asio/thread.hpp"
@ -304,7 +305,8 @@ void io_context_run(asio::io_context* ioc)
void deadline_timer_thread_test()
{
asio::io_context ioc;
asio::io_context::work w(ioc);
asio::executor_work_guard<asio::io_context::executor_type> work
= asio::make_work_guard(ioc);
asio::deadline_timer t1(ioc);
asio::deadline_timer t2(ioc);
int count = 0;

View File

@ -150,7 +150,7 @@ void io_context_test()
count = 0;
ioc.restart();
io_context::work* w = new io_context::work(ioc);
executor_work_guard<io_context::executor_type> w = make_work_guard(ioc);
asio::post(ioc, bindns::bind(&io_context::stop, &ioc));
ASIO_CHECK(!ioc.stopped());
ioc.run();
@ -161,7 +161,7 @@ void io_context_test()
ioc.restart();
asio::post(ioc, bindns::bind(increment, &count));
delete w;
w.reset();
// No handlers can be called until run() is called.
ASIO_CHECK(!ioc.stopped());

View File

@ -25,6 +25,7 @@
#if defined(ASIO_HAS_STD_CHRONO)
#include "asio/executor_work_guard.hpp"
#include "asio/io_context.hpp"
#include "asio/thread.hpp"
@ -325,7 +326,8 @@ void io_context_run(asio::io_context* ioc)
void system_timer_thread_test()
{
asio::io_context ioc;
asio::io_context::work w(ioc);
asio::executor_work_guard<asio::io_context::executor_type> work
= asio::make_work_guard(ioc);
asio::system_timer t1(ioc);
asio::system_timer t2(ioc);
int count = 0;