Skip to content

Commit

Permalink
[hosted] Fix deprecated use of boost::asio::io_service
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Dec 18, 2024
1 parent 0cb8045 commit ddf1b2a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/modm/platform/uart/hosted/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ def build(env):
# FIXME: boost/type_traits/detail/config.hpp:85:69: warning: "__clang_major___WORKAROUND_GUARD" is not defined, evaluates to 0
env.collect(":build:cppdefines.release", "__clang_major___WORKAROUND_GUARD=4")

env.collect(":build:library", "boost_system")
env.collect(":build:library", "boost_system", "boost_thread")
if env[":target"].identifier.family == "linux":
env.collect(":build:library", "boost_thread", "pthread")
else:
env.collect(":build:library", "boost_thread-mt")
env.collect(":build:library", "pthread")

env.outbasepath = "modm/src/modm/platform/uart"
env.copy(".")
16 changes: 8 additions & 8 deletions src/modm/platform/uart/hosted/serial_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

modm::platform::SerialPort::SerialPort():
shutdown(true),
port(io_service)
port(io_context)
{
}

Expand All @@ -28,7 +28,7 @@ modm::platform::SerialPort::~SerialPort()
void
modm::platform::SerialPort::write(char c)
{
this->io_service.post(boost::bind(&modm::platform::SerialPort::doWrite, this, c));
boost::asio::post(this->io_context, boost::bind(&modm::platform::SerialPort::doWrite, this, c));
}


Expand Down Expand Up @@ -84,9 +84,9 @@ modm::platform::SerialPort::open(std::string deviceName, unsigned int baudRate)
this->port.set_option(boost::asio::serial_port_base::character_size(8));
this->port.set_option(boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one));

this->io_service.post(boost::bind(&SerialPort::readStart, this));
boost::asio::post(this->io_context, boost::bind(&SerialPort::readStart, this));

this->thread = new boost::thread(boost::bind(&boost::asio::io_service::run, &this->io_service));
this->thread = new boost::thread(boost::bind(&boost::asio::io_context::run, &this->io_context));
}
else {
std::cerr << "Port already open!" << std::endl;
Expand All @@ -108,14 +108,14 @@ modm::platform::SerialPort::close()
if (!this->isOpen())
return;

this->io_service.post(boost::bind(
boost::asio::post(this->io_context, boost::bind(
&modm::platform::SerialPort::doClose,
this,
boost::system::error_code()));

this->thread->join();
delete this->thread;
this->io_service.reset();
this->io_context.restart();
}

void
Expand All @@ -124,14 +124,14 @@ modm::platform::SerialPort::kill()
if (!this->isOpen())
return;

this->io_service.post(boost::bind(
boost::asio::post(this->io_context, boost::bind(
&modm::platform::SerialPort::doAbort,
this,
boost::system::error_code()));
this->shutdown = true;
this->thread->join();
delete this->thread;
this->io_service.reset();
this->io_context.restart();
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/uart/hosted/serial_port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace modm
std::queue<char> writeBuffer;
std::queue<char> readBuffer;

boost::asio::io_service io_service;
boost::asio::io_context io_context;
boost::asio::serial_port port;
boost::thread* thread;

Expand Down

0 comments on commit ddf1b2a

Please sign in to comment.