Skip to content

Commit

Permalink
Fix frame sync issue in OBCameraNode and add try lock in deviceConnec…
Browse files Browse the repository at this point in the history
…tCallback
  • Loading branch information
jian-dong committed Oct 19, 2024
1 parent 837cb42 commit 04cf221
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ob_camera_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ void OBCameraNode::startStreams() {
ROS_INFO_STREAM("====Enable frame sync====");
pipeline_->enableFrameSync();
} else {
ROS_INFO_STREAM("====Disable frame sync====");
pipeline_->disableFrameSync();
}
try {
Expand Down
15 changes: 14 additions & 1 deletion src/ob_camera_node_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,20 @@ void OBCameraNodeDriver::deviceConnectCallback(const std::shared_ptr<ob::DeviceL
try {
std::this_thread::sleep_for(std::chrono::milliseconds(connection_delay_));
ROS_INFO_STREAM("deviceConnectCallback : Before process lock lock");
pthread_mutex_lock(orb_device_lock_);
// use try lock to avoid deadlock
int max_try_lock_count = 5;
int try_lock_count = 0;
for (; try_lock_count < max_try_lock_count; try_lock_count++) {
if (pthread_mutex_trylock(orb_device_lock_) == 0) {
break;
}
ROS_WARN_STREAM("deviceConnectCallback : Failed to lock orb_device_lock_, wait for 100ms");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
if (try_lock_count == max_try_lock_count) {
ROS_ERROR_STREAM("deviceConnectCallback : Failed to lock orb_device_lock_, return");
return;
}
ROS_INFO_STREAM("deviceConnectCallback : After process lock lock");
std::shared_ptr<int> lock_guard(nullptr,
[this](int *) { pthread_mutex_unlock(orb_device_lock_); });
Expand Down

0 comments on commit 04cf221

Please sign in to comment.