mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-11 06:59:49 +08:00
Fix device lock issue in OBCameraNodeDriver::startDevice
This commit is contained in:
@@ -472,7 +472,16 @@ void OBCameraNodeDriver::startDevice(const std::shared_ptr<ob::DeviceList> &list
|
|||||||
device_.reset();
|
device_.reset();
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(connection_delay_));
|
std::this_thread::sleep_for(std::chrono::milliseconds(connection_delay_));
|
||||||
pthread_mutex_lock(orb_device_lock_);
|
auto try_lock_result = pthread_mutex_trylock(orb_device_lock_);
|
||||||
|
if (try_lock_result != 0) {
|
||||||
|
if (try_lock_result == EBUSY) {
|
||||||
|
RCLCPP_INFO_STREAM(logger_, "Device lock locked by other process, wait for 10ms");
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
} else {
|
||||||
|
RCLCPP_ERROR_STREAM(logger_, "Failed to lock orb_device_lock_");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
std::shared_ptr<int> lock_holder(nullptr,
|
std::shared_ptr<int> lock_holder(nullptr,
|
||||||
[this](int *) { pthread_mutex_unlock(orb_device_lock_); });
|
[this](int *) { pthread_mutex_unlock(orb_device_lock_); });
|
||||||
bool start_device_failed = false;
|
bool start_device_failed = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user