change sem to pthread lock

This commit is contained in:
Joe Dong
2023-09-15 10:30:23 +08:00
parent 4f78ec5b51
commit 23068e428d
7 changed files with 57 additions and 186 deletions
@@ -110,7 +110,6 @@ const int32_t OPENNI_END_PID = 0x06FF;
const int32_t ASTRA_MINI_PID = 0x0404;
const int32_t ASTRA_MINI_S_PID = 0x0407;
const int GEMINI2_PID = 0x0670;
const std::string DEFAULT_SEM_NAME = "orbbec_device_sem";
const key_t DEFAULT_SEM_KEY = 0x0401;
const std::string ORB_DEFAULT_LOCK_NAME = "orbbec_device_lock";
} // namespace orbbec_camera
@@ -1,18 +1,18 @@
/*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
* Copyright (c) 2023 Orbbec 3D Technology, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#pragma once
#include <atomic>
#include <thread>
@@ -24,17 +24,10 @@
#include "dynamic_params.h"
#include "libobsensor/ObSensor.hpp"
#include <pthread.h>
namespace orbbec_camera {
enum DeviceConnectionEvent {
kDeviceConnected = 0,
kDeviceDisconnected,
kOtherDeviceConnected,
kOtherDeviceDisconnected,
kDeviceCountUpdate,
};
class OBCameraNodeDriver : public rclcpp::Node {
public:
explicit OBCameraNodeDriver(const rclcpp::NodeOptions& node_options = rclcpp::NodeOptions());
@@ -45,11 +38,6 @@ class OBCameraNodeDriver : public rclcpp::Node {
private:
void init();
void releaseDeviceSemaphore(sem_t* device_sem, int& num_devices_connected);
void updateConnectedDeviceCount(int& num_devices_connected,
DeviceConnectionEvent connection_event);
std::shared_ptr<ob::Device> selectDevice(const std::shared_ptr<ob::DeviceList>& list);
std::shared_ptr<ob::Device> selectDeviceBySerialNumber(
@@ -72,8 +60,6 @@ class OBCameraNodeDriver : public rclcpp::Node {
void queryDevice();
void deviceCountUpdate();
void syncTime();
void resetDevice();
@@ -95,12 +81,16 @@ class OBCameraNodeDriver : public rclcpp::Node {
std::shared_ptr<std::thread> device_count_update_thread_ = nullptr;
std::recursive_mutex device_lock_;
int device_num_ = 1;
int num_devices_connected_ = 0;
rclcpp::TimerBase::SharedPtr check_connect_timer_ = nullptr;
std::shared_ptr<std::thread> sync_time_thread_ = nullptr;
std::shared_ptr<std::thread> reset_device_thread_ = nullptr;
std::mutex reset_device_mutex_;
std::condition_variable reset_device_cond_;
std::atomic_bool reset_device_flag_{false};
pthread_mutex_t* orb_device_lock_ = nullptr;
sem_t* orb_device_sem_ = nullptr;
pthread_mutexattr_t orb_device_lock_attr_;
uint8_t* orb_device_lock_shm_addr_ = nullptr;
int orb_device_lock_shm_fd_ = -1;
};
} // namespace orbbec_camera