mirror of
https://github.com/latentPrion/libspinscale.git
synced 2026-06-23 19:48:32 +00:00
Boost.ASIO: update io_service=>io_context
This commit is contained in:
+7
-7
@@ -27,10 +27,10 @@ void PuppetComponent::defaultPuppetMain(
|
||||
if (args.preJoltHook) { args.preJoltHook(thr); }
|
||||
|
||||
/** FIXME:
|
||||
* Figure out why we don't call reset() here, and then explicitly document
|
||||
* Figure out why we don't call restart() here, and then explicitly document
|
||||
* it.
|
||||
*/
|
||||
thr.getIoService().run();
|
||||
thr.getIoContext().run();
|
||||
thr.initializeTls();
|
||||
|
||||
comp.postJoltHook();
|
||||
@@ -52,15 +52,15 @@ void PuppetComponent::defaultPuppetMain(
|
||||
/** EXPLANATION:
|
||||
* This reset() call is crucial for async bridging patterns
|
||||
* to work.
|
||||
* When the outermost thread's io_service is stop()ped (e.g.,
|
||||
* When the outermost thread's io_context is stop()ped (e.g.,
|
||||
* from JOLT sequence), it won't process any new work until
|
||||
* reset() is called, even if nested async operations try to
|
||||
* restart() is called, even if nested async operations try to
|
||||
* post work to it. This means async bridges invoked from
|
||||
* the outermost thread main sequence won't work until this
|
||||
* reset() call.
|
||||
* restart() call.
|
||||
*/
|
||||
thr.getIoService().reset();
|
||||
thr.getIoService().run();
|
||||
thr.getIoContext().restart();
|
||||
thr.getIoContext().run();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
||||
+16
-16
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <spinscale/cps/asynchronousContinuation.h>
|
||||
#include <spinscale/cps/callback.h>
|
||||
#include <spinscale/cps/callableTracer.h>
|
||||
@@ -49,7 +49,7 @@ std::shared_ptr<PuppeteerThread> ComponentThread::getPptr()
|
||||
void PuppeteerThread::exitLoop(void)
|
||||
{
|
||||
keepLooping = false;
|
||||
getIoService().stop();
|
||||
getIoContext().stop();
|
||||
std::cout << name << ": Signaled main loop to exit." << "\n";
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
"JOLT request."
|
||||
<< "\n";
|
||||
|
||||
target->io_service.stop();
|
||||
target->io_context.stop();
|
||||
callOriginalCb();
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
"exitThread (main queue)." << "\n";
|
||||
|
||||
target->cleanup();
|
||||
target->io_service.stop();
|
||||
target->io_context.stop();
|
||||
callOriginalCb();
|
||||
}
|
||||
|
||||
@@ -142,8 +142,8 @@ public:
|
||||
"exitThread (pause queue)."<< "\n";
|
||||
|
||||
target->cleanup();
|
||||
target->pause_io_service.stop();
|
||||
target->io_service.stop();
|
||||
target->pause_io_context.stop();
|
||||
target->io_context.stop();
|
||||
callOriginalCb();
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ public:
|
||||
* have a chance to invoke the callback until it's unblocked.
|
||||
*/
|
||||
callOriginalCb();
|
||||
target->pause_io_service.reset();
|
||||
target->pause_io_service.run();
|
||||
target->pause_io_context.restart();
|
||||
target->pause_io_context.run();
|
||||
}
|
||||
|
||||
void resumeThreadReq1_posted(
|
||||
@@ -170,7 +170,7 @@ public:
|
||||
std::cout << __func__ << ": Thread '" << target->name << "': handling "
|
||||
"resumeThread." << "\n";
|
||||
|
||||
target->pause_io_service.stop();
|
||||
target->pause_io_context.stop();
|
||||
callOriginalCb();
|
||||
}
|
||||
};
|
||||
@@ -210,7 +210,7 @@ void PuppetThread::joltThreadReq(
|
||||
auto request = std::make_shared<ThreadLifetimeMgmtOp>(
|
||||
puppeteer, selfPtr, callback);
|
||||
|
||||
this->getIoService().post(
|
||||
boost::asio::post(this->getIoContext(),
|
||||
STC(std::bind(
|
||||
&ThreadLifetimeMgmtOp::joltThreadReq1_posted,
|
||||
request.get(), request)));
|
||||
@@ -224,7 +224,7 @@ void PuppetThread::startThreadReq(cps::Callback<threadLifetimeMgmtOpCbFn> callba
|
||||
caller, std::static_pointer_cast<PuppetThread>(shared_from_this()),
|
||||
callback);
|
||||
|
||||
this->getIoService().post(
|
||||
boost::asio::post(this->getIoContext(),
|
||||
STC(std::bind(
|
||||
&ThreadLifetimeMgmtOp::startThreadReq1_posted,
|
||||
request.get(), request)));
|
||||
@@ -237,12 +237,12 @@ void PuppetThread::exitThreadReq(cps::Callback<threadLifetimeMgmtOpCbFn> callbac
|
||||
caller, std::static_pointer_cast<PuppetThread>(shared_from_this()),
|
||||
callback);
|
||||
|
||||
this->getIoService().post(
|
||||
boost::asio::post(this->getIoContext(),
|
||||
STC(std::bind(
|
||||
&ThreadLifetimeMgmtOp::exitThreadReq1_mainQueue_posted,
|
||||
request.get(), request)));
|
||||
|
||||
pause_io_service.post(
|
||||
boost::asio::post(pause_io_context,
|
||||
STC(std::bind(
|
||||
&ThreadLifetimeMgmtOp::exitThreadReq1_pauseQueue_posted,
|
||||
request.get(), request)));
|
||||
@@ -261,7 +261,7 @@ void PuppetThread::pauseThreadReq(cps::Callback<threadLifetimeMgmtOpCbFn> callba
|
||||
caller, std::static_pointer_cast<PuppetThread>(shared_from_this()),
|
||||
callback);
|
||||
|
||||
this->getIoService().post(
|
||||
boost::asio::post(this->getIoContext(),
|
||||
STC(std::bind(
|
||||
&ThreadLifetimeMgmtOp::pauseThreadReq1_posted,
|
||||
request.get(), request)));
|
||||
@@ -275,13 +275,13 @@ void PuppetThread::resumeThreadReq(cps::Callback<threadLifetimeMgmtOpCbFn> callb
|
||||
+ ": invoked on puppeteer thread");
|
||||
}
|
||||
|
||||
// Post to the pause_io_service to unblock the paused thread
|
||||
// Post to the pause_io_context to unblock the paused thread
|
||||
std::shared_ptr<ComponentThread> caller = getSelf();
|
||||
auto request = std::make_shared<ThreadLifetimeMgmtOp>(
|
||||
caller, std::static_pointer_cast<PuppetThread>(shared_from_this()),
|
||||
callback);
|
||||
|
||||
pause_io_service.post(
|
||||
boost::asio::post(pause_io_context,
|
||||
STC(std::bind(
|
||||
&ThreadLifetimeMgmtOp::resumeThreadReq1_posted,
|
||||
request.get(), request)));
|
||||
|
||||
@@ -16,8 +16,8 @@ void PuppeteerComponent::defaultPuppeteerMain(
|
||||
|
||||
if (args.preJoltHook) { args.preJoltHook(thr); }
|
||||
|
||||
thr.getIoService().reset();
|
||||
thr.getIoService().run();
|
||||
thr.getIoContext().restart();
|
||||
thr.getIoContext().run();
|
||||
thr.initializeTls();
|
||||
|
||||
comp.postJoltHook();
|
||||
@@ -40,17 +40,17 @@ void PuppeteerComponent::defaultPuppeteerMain(
|
||||
|
||||
try {
|
||||
/** EXPLANATION:
|
||||
* This reset() call is crucial for async bridging
|
||||
* This restart() call is crucial for async bridging
|
||||
* patterns to work.
|
||||
* When the outermost thread's io_service is stop()ped
|
||||
* When the outermost thread's io_context is stop()ped
|
||||
* (e.g., from JOLT sequence), it won't process any new
|
||||
* work until reset() is called, even if nested async
|
||||
* work until restart() is called, even if nested async
|
||||
* operations try to post work to it. This means async
|
||||
* bridges invoked from the outermost thread main sequence
|
||||
* won't work until this reset() call.
|
||||
* won't work until this restart() call.
|
||||
*/
|
||||
thr.getIoService().reset();
|
||||
thr.getIoService().run();
|
||||
thr.getIoContext().restart();
|
||||
thr.getIoContext().run();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
||||
+3
-3
@@ -288,8 +288,8 @@ void Qutex::backoff(
|
||||
* (Assume that Lv2 was not at the front of the common qutex's
|
||||
* internal queue -- it only needed to be in the top 66%.)
|
||||
* Lv1 tries to acquire the common lock and fails. It gets taken off of
|
||||
* its io_service. It's now asleep until it gets
|
||||
* re-added into an io_service.
|
||||
* its io_context. It's now asleep until it gets
|
||||
* re-added into an io_context.
|
||||
* Lv2 fails to acquire the other 2 locks it needs and backoff()s from
|
||||
* the common lock it shares with Lv1.
|
||||
*
|
||||
@@ -357,7 +357,7 @@ void Qutex::release()
|
||||
* Just before Lv1 can acquire the common lock, Lv2 acquires it now,
|
||||
* because it only needs to be in the top 66% to succeed.
|
||||
* Lv1 checks the currOwner and sees that it's owned. Lv1 is now
|
||||
* dequeued from its io_service. It won't be awakened until someone
|
||||
* dequeued from its io_context. It won't be awakened until someone
|
||||
* awakens it.
|
||||
* Lv2 finishes its critical section and releas()es the common lock.
|
||||
* Lv2 was not at the front of the qutexQ, so it does NOT awaken the
|
||||
|
||||
Reference in New Issue
Block a user