Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions libsrc/eclib/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include <stdlib.h>
#include <boost/thread/thread.hpp>
#include <boost/thread/future.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/post.hpp>
#include <boost/shared_ptr.hpp>

class threadpool {
Expand Down Expand Up @@ -61,7 +62,7 @@ class threadpool {
}

// Add reference to new task to job queue
io_service_.post( boost::bind< void >( boost::ref( task ) ) );
boost::asio::post(io_context_, boost::bind< void >( boost::ref( task ) ) );
}

unsigned int getThreadCount();
Expand All @@ -72,8 +73,8 @@ class threadpool {
unsigned int threadCount_;
int verbose_;

boost::asio::io_service io_service_;
boost::shared_ptr< boost::asio::io_service::work > work_;
boost::asio::io_context io_context_;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work_;
boost::thread_group threads_;

};
Expand Down
10 changes: 5 additions & 5 deletions libsrc/threadpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
threadpool::threadpool()
: maxThreads_( 0 ), threadCount_( 0 ), verbose_( -1 ),
work_( new boost::asio::io_service::work( io_service_ ) )
work_( boost::asio::make_work_guard( io_context_ ) )
{}

/**
Expand All @@ -56,7 +56,7 @@ threadpool::threadpool()
* Main constructor.
*/
threadpool::threadpool( unsigned int numThreads, int verbose )
: work_( new boost::asio::io_service::work( io_service_ ) ) {
: work_( boost::asio::make_work_guard( io_context_ ) ) {
start( numThreads, verbose );
}

Expand Down Expand Up @@ -104,7 +104,7 @@ void threadpool::start( unsigned int numThreads, int verbose ) {

// Create threads and add to threadpool
for( unsigned int i = 0; i < threadCount_-1; i++ ) {
threads_.create_thread( boost::bind( &boost::asio::io_service::run, &io_service_ ) );
threads_.create_thread( boost::bind( &boost::asio::io_context::run, &io_context_ ) );
}
}

Expand All @@ -127,10 +127,10 @@ void threadpool::close() {
work_.reset();

// run() blocks until all posted jobs have finished
io_service_.run();
io_context_.run();

// We close the threadpool and join all threads
io_service_.stop();
io_context_.stop();
threads_.join_all();
}

Expand Down
2 changes: 1 addition & 1 deletion m4/ax_boost_asio.m4
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ AC_DEFUN([AX_BOOST_ASIO],
]],
[[

boost::asio::io_service io;
boost::asio::io_context io;
boost::system::error_code timer_result;
boost::asio::deadline_timer t(io);
t.cancel();
Expand Down
Loading