mirror of
https://github.com/westonrobot/ugv_sdk
synced 2023-04-08 06:32:14 +08:00
async_port: fixed resource release order issue in StopService()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user