async_port: fixed resource release order issue in StopService()

This commit is contained in:
Ruixiang Du
2021-09-02 17:06:42 +08:00
parent a8051f1bd9
commit c5faa29368
2 changed files with 9 additions and 9 deletions

View File

@@ -76,15 +76,15 @@ bool AsyncCAN::SetupPort() {
}
void AsyncCAN::StopService() {
// release port fd
const int close_result = ::close(can_fd_);
can_fd_ = -1;
// stop io thread
io_context_.stop();
if (io_thread_.joinable()) io_thread_.join();
io_context_.reset();
// release port fd
const int close_result = ::close(can_fd_);
can_fd_ = -1;
port_opened_ = false;
}

View File

@@ -71,16 +71,16 @@ bool AsyncSerial::SetupPort() {
}
void AsyncSerial::StopService() {
if (IsOpened()) {
serial_port_.cancel();
serial_port_.close();
}
// stop io thread
io_context_.stop();
if (io_thread_.joinable()) io_thread_.join();
io_context_.reset();
if (IsOpened()) {
serial_port_.cancel();
serial_port_.close();
}
port_opened_ = false;
}