Skip to content

Commit e6a3768

Browse files
Migrate to boost::asio::io_context
The code previously used the deprecated (and with bost 1.87.0 removed) `boost::asio::io_service`, which used to be an alias to `io_context`. The new version heavily changes the `io_context` API and therefore is no the old interface was removed. Fixes #208 Signed-off-by: Christian Heusel <[email protected]>
1 parent 76dc90f commit e6a3768

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

include/lucene++/ThreadPool.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
namespace Lucene {
1616

17-
typedef boost::shared_ptr<boost::asio::io_service::work> workPtr;
17+
18+
typedef boost::asio::io_context io_context_t;
19+
typedef boost::asio::executor_work_guard<io_context_t::executor_type> work_t;
1820

1921
/// A Future represents the result of an asynchronous computation. Methods are provided to check if the computation
2022
/// is complete, to wait for its completion, and to retrieve the result of the computation. The result can only be
@@ -51,8 +53,8 @@ class ThreadPool : public LuceneObject {
5153
LUCENE_CLASS(ThreadPool);
5254

5355
protected:
54-
boost::asio::io_service io_service;
55-
workPtr work;
56+
io_context_t io_context;
57+
work_t work;
5658
boost::thread_group threadGroup;
5759

5860
static const int32_t THREADPOOL_SIZE;
@@ -64,7 +66,7 @@ class ThreadPool : public LuceneObject {
6466
template <typename FUNC>
6567
FuturePtr scheduleTask(FUNC func) {
6668
FuturePtr future(newInstance<Future>());
67-
io_service.post(boost::bind(&ThreadPool::execute<FUNC>, this, func, future));
69+
boost::asio::post(io_context, boost::bind(&ThreadPool::execute<FUNC>, this, func, future));
6870
return future;
6971
}
7072

src/core/util/ThreadPool.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ Future::~Future() {
1414

1515
const int32_t ThreadPool::THREADPOOL_SIZE = 5;
1616

17-
ThreadPool::ThreadPool() {
18-
work.reset(new boost::asio::io_service::work(io_service));
17+
ThreadPool::ThreadPool()
18+
:
19+
work(boost::asio::make_work_guard(io_context))
20+
{
1921
for (int32_t i = 0; i < THREADPOOL_SIZE; ++i) {
20-
threadGroup.create_thread(boost::bind(&boost::asio::io_service::run, &io_service));
22+
threadGroup.create_thread(boost::bind(&boost::asio::io_context::run, &io_context));
2123
}
2224
}
2325

2426
ThreadPool::~ThreadPool() {
25-
work.reset(); // stop all threads
2627
threadGroup.join_all(); // wait for all competition
2728
}
2829

0 commit comments

Comments
 (0)