From: Mu-Woong Lee Date: Wed, 3 Feb 2016 07:45:42 +0000 (+0900) Subject: sensor-plugin-tm1: remove useless lock X-Git-Tag: accepted/tizen/mobile/20160217.080647^2~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F58742%2F1;p=platform%2Fadaptation%2Ftm1%2Fsensor-hal-tm1.git sensor-plugin-tm1: remove useless lock HAL developer doesn't need to consider lock mechanism * It is started to refactoring sensor HAL for supporting sensorhub from this patch. Change-Id: Ib594af73a741d1805f2a35e995ccebd110e89ddc Signed-off-by: kibak.yoon Signed-off-by: Mu-Woong Lee --- diff --git a/packaging/sensor-plugins-tm1.spec b/packaging/sensor-plugins-tm1.spec index 5321ac7..294400c 100644 --- a/packaging/sensor-plugins-tm1.spec +++ b/packaging/sensor-plugins-tm1.spec @@ -18,7 +18,7 @@ BuildRequires: pkgconfig(libxml-2.0) %define accel_state ON %define gyro_state OFF -%define proxi_state ON +%define proxi_state OFF %define light_state OFF %define geo_state OFF %define pressure_state OFF diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c71b78e..caf9ea1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,9 +73,7 @@ configure_file(hal_module_create.cpp.in hal_module_create.cpp) add_library(${PROJECT_NAME} SHARED ${SRCS} - lib/cbase_lock.cpp lib/cconfig.cpp - lib/cmutex.cpp lib/csensor_config.cpp lib/sensor_logs.cpp interface/sensor_hal_base.cpp diff --git a/src/interface/sensor_hal_base.cpp b/src/interface/sensor_hal_base.cpp index 30147c9..d50d59d 100644 --- a/src/interface/sensor_hal_base.cpp +++ b/src/interface/sensor_hal_base.cpp @@ -28,8 +28,6 @@ using std::ofstream; using std::fstream; using std::string; -cmutex sensor_hal_base::m_shared_mutex; - sensor_hal_base::sensor_hal_base() { } @@ -211,8 +209,6 @@ bool sensor_hal_base::set_enable_node(const string &node_path, bool sensorhub_co { int prev_status, status; - AUTOLOCK(m_shared_mutex); - if (!get_node_value(node_path, prev_status)) { ERR("Failed to get node: %s", node_path.c_str()); return false; diff --git a/src/interface/sensor_hal_base.h b/src/interface/sensor_hal_base.h index ee53879..cfa714c 100644 --- a/src/interface/sensor_hal_base.h +++ b/src/interface/sensor_hal_base.h @@ -21,7 +21,6 @@ #define _SENSOR_HAL_BASE_H_ #include #include -#include #include #include #include @@ -79,9 +78,6 @@ public: int send_sensorhub_data(const char *data, int data_len); protected: - cmutex m_mutex; - static cmutex m_shared_mutex; - bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0); static unsigned long long get_timestamp(void); diff --git a/src/lib/cbase_lock.cpp b/src/lib/cbase_lock.cpp deleted file mode 100755 index 5a1a639..0000000 --- a/src/lib/cbase_lock.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * 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. - * - */ - -#include -#include -#include -#include -#include -#include - - -cbase_lock::cbase_lock() -{ - m_history_mutex = PTHREAD_MUTEX_INITIALIZER; -} - -cbase_lock::~cbase_lock() -{ - pthread_mutex_destroy(&m_history_mutex); -} - -void cbase_lock::lock(lock_type type, const char* expr, const char *module, const char *func, int line) -{ - int ret = 0; - char m_curent_info[OWNER_INFO_LEN]; - struct timeval sv; - unsigned long long lock_waiting_start_time = 0; - unsigned long long lock_acquired_time = 0; - unsigned long long waiting_time = 0; - - - snprintf(m_curent_info, OWNER_INFO_LEN, "%s:%s(%d)", module, func, line); - - if (type == LOCK_TYPE_MUTEX) - ret = try_lock_impl(); - else if (type == LOCK_TYPE_READ) - ret = try_read_lock_impl(); - else if (type == LOCK_TYPE_WRITE) - ret = try_write_lock_impl(); - - if (ret == 0) { - pthread_mutex_lock(&m_history_mutex); - snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info); - pthread_mutex_unlock(&m_history_mutex); - return; - } - - gettimeofday(&sv, NULL); - lock_waiting_start_time = MICROSECONDS(sv); - - pthread_mutex_lock(&m_history_mutex); - INFO("%s is waiting for getting %s(0x%x) owned in %s", - m_curent_info, expr, this, m_owner_info); - pthread_mutex_unlock(&m_history_mutex); - - - if (type == LOCK_TYPE_MUTEX) - lock_impl(); - else if (type == LOCK_TYPE_READ) - read_lock_impl(); - else if (type == LOCK_TYPE_WRITE) - write_lock_impl(); - - gettimeofday(&sv, NULL); - lock_acquired_time = MICROSECONDS(sv); - - waiting_time = lock_acquired_time - lock_waiting_start_time; - - pthread_mutex_lock(&m_history_mutex); - INFO("%s acquires lock after waiting %lluus, %s(0x%x) was previously owned in %s", - m_curent_info, waiting_time, expr, this, m_owner_info); - snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info); - pthread_mutex_unlock(&m_history_mutex); -} - - -void cbase_lock::lock(lock_type type) -{ - if (type == LOCK_TYPE_MUTEX) - lock_impl(); - else if (type == LOCK_TYPE_READ) - read_lock_impl(); - else if (type == LOCK_TYPE_WRITE) - write_lock_impl(); -} - -void cbase_lock::unlock(void) -{ - unlock_impl(); -} - - -int cbase_lock::lock_impl(void) -{ - return 0; -} - -int cbase_lock::read_lock_impl(void) -{ - return 0; -} - -int cbase_lock::write_lock_impl(void) -{ - return 0; -} - -int cbase_lock::try_lock_impl(void) -{ - return 0; -} - -int cbase_lock::try_read_lock_impl(void) -{ - return 0; -} - -int cbase_lock::try_write_lock_impl(void) -{ - return 0; -} - -int cbase_lock::unlock_impl(void) -{ - return 0; -} - -Autolock::Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line) -: m_lock(m) -{ - m_lock.lock(type, expr, module, func, line); -} - -Autolock::Autolock(cbase_lock &m, lock_type type) -: m_lock(m) -{ - m_lock.lock(type); -} - -Autolock::~Autolock() -{ - m_lock.unlock(); -} diff --git a/src/lib/cbase_lock.h b/src/lib/cbase_lock.h deleted file mode 100755 index 2b0082a..0000000 --- a/src/lib/cbase_lock.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * 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. - * - */ - -#if !defined(_CBASE_LOCK_CLASS_H_) -#define _CBASE_LOCK_CLASS_H_ - -#include - -enum lock_type { - LOCK_TYPE_MUTEX, - LOCK_TYPE_READ, - LOCK_TYPE_WRITE, -}; - -#ifdef _LOCK_DEBUG -#define AUTOLOCK(x) Autolock x##_autolock((x),LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__) -#define AUTOLOCK_R(x) Autolock x##_autolock_r((x),LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__) -#define AUTOLOCK_W(x) Autolock x##_autolock_w((x),LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__) -#define LOCK(x) (x).lock(#x, __MODULE__, __func__, __LINE__) -#define LOCK_R(x) (x).lock(LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__) -#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__) -#define UNLOCK(x) (x).unlock() -#else -#define AUTOLOCK(x) Autolock x##_autolock((x),LOCK_TYPE_MUTEX) -#define AUTOLOCK_R(x) Autolock x##_autolock_r((x),LOCK_TYPE_READ) -#define AUTOLOCK_W(x) Autolock x##_autolock_w((x),LOCK_TYPE_WRITE) -#define LOCK(x) (x).lock() -#define LOCK_R(x) (x).lock(LOCK_TYPE_READ) -#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE) -#define UNLOCK(x) (x).unlock() -#endif - - -class cbase_lock -{ -public: - cbase_lock(); - virtual ~cbase_lock(); - - void lock(lock_type type, const char* expr, const char *module, const char *func, int line); - void lock(lock_type type); - void unlock(void); - -protected: - virtual int lock_impl(void); - virtual int read_lock_impl(void); - virtual int write_lock_impl(void); - - virtual int try_lock_impl(void); - virtual int try_read_lock_impl(void); - virtual int try_write_lock_impl(void); - - virtual int unlock_impl(void); -private: - pthread_mutex_t m_history_mutex; - static const int OWNER_INFO_LEN = 256; - char m_owner_info[OWNER_INFO_LEN]; -}; - -class Autolock -{ -private: - cbase_lock& m_lock; -public: - Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line); - Autolock(cbase_lock &m, lock_type type); - ~Autolock(); -}; - -#endif -// End of a file diff --git a/src/lib/cmutex.cpp b/src/lib/cmutex.cpp deleted file mode 100755 index fb09f7c..0000000 --- a/src/lib/cmutex.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * 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. - * - */ - -#include -#include "sensor_logs.h" - -cmutex::cmutex() -{ - pthread_mutexattr_t mutex_attr; - pthread_mutexattr_init(&mutex_attr); - pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&m_mutex, &mutex_attr); - pthread_mutexattr_destroy(&mutex_attr); -} - -cmutex::~cmutex() -{ - pthread_mutex_destroy(&m_mutex); -} - -void cmutex::lock() -{ -#ifdef _LOCK_DEBUG - cbase_lock::lock(LOCK_TYPE_MUTEX, "mutex", __MODULE__, __func__, __LINE__); -#else - cbase_lock::lock(LOCK_TYPE_MUTEX); -#endif -} - -void cmutex::lock(const char* expr, const char *module, const char *func, int line) -{ - cbase_lock::lock(LOCK_TYPE_MUTEX, expr, module, func, line); -} - -int cmutex::lock_impl(void) -{ - return pthread_mutex_lock(&m_mutex); -} - -int cmutex::try_lock_impl(void) -{ - return pthread_mutex_trylock(&m_mutex); - -} - -int cmutex::unlock_impl() -{ - return pthread_mutex_unlock(&m_mutex); -} diff --git a/src/lib/cmutex.h b/src/lib/cmutex.h deleted file mode 100755 index bfdd5d0..0000000 --- a/src/lib/cmutex.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * libsensord-share - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * 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. - * - */ - -#if !defined(_CMUTEX_CLASS_H_) -#define _CMUTEX_CLASS_H_ - -#include "cbase_lock.h" - -class cmutex : public cbase_lock -{ -public: - cmutex(); - virtual ~cmutex(); - - void lock(void); - void lock(const char* expr, const char *module, const char *func, int line); - -protected: - int lock_impl(void); - int try_lock_impl(void); - int unlock_impl(); -private: - pthread_mutex_t m_mutex; -}; - -#endif -// End of a file diff --git a/src/plugins/accel/accel_sensor_hal.cpp b/src/plugins/accel/accel_sensor_hal.cpp index af21cb3..58441b2 100755 --- a/src/plugins/accel/accel_sensor_hal.cpp +++ b/src/plugins/accel/accel_sensor_hal.cpp @@ -165,8 +165,6 @@ sensor_hal_type_t accel_sensor_hal::get_type(void) bool accel_sensor_hal::enable(void) { - AUTOLOCK(m_mutex); - set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT); set_interval(m_polling_interval); @@ -177,8 +175,6 @@ bool accel_sensor_hal::enable(void) bool accel_sensor_hal::disable(void) { - AUTOLOCK(m_mutex); - set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT); INFO("Accel sensor real stopping"); @@ -188,9 +184,6 @@ bool accel_sensor_hal::disable(void) bool accel_sensor_hal::set_interval(unsigned long val) { unsigned long long polling_interval_ns; - - AUTOLOCK(m_mutex); - polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu); if (!set_node_value(m_interval_node, polling_interval_ns)) { @@ -259,8 +252,6 @@ bool accel_sensor_hal::update_value_input_event() return false; } - AUTOLOCK(m_value_mutex); - if (x) m_x = accel_raw[0]; if (y) @@ -313,8 +304,6 @@ bool accel_sensor_hal::update_value_iio() return false; } - AUTOLOCK(m_value_mutex); - short *short_data = (short *)(data); m_x = *(short_data); m_y = *((short *)(data + 2)); @@ -325,7 +314,6 @@ bool accel_sensor_hal::update_value_iio() INFO("m_x = %d, m_y = %d, m_z = %d, time = %lluus", m_x, m_y, m_z, m_fired_time); return true; - } bool accel_sensor_hal::is_data_ready(void) @@ -337,8 +325,6 @@ bool accel_sensor_hal::is_data_ready(void) int accel_sensor_hal::get_sensor_data(sensor_data_t &data) { - AUTOLOCK(m_value_mutex); - data.accuracy = SENSOR_ACCURACY_GOOD; data.timestamp = m_fired_time; data.value_count = 3; diff --git a/src/plugins/accel/accel_sensor_hal.h b/src/plugins/accel/accel_sensor_hal.h index 97c4af4..3161922 100755 --- a/src/plugins/accel/accel_sensor_hal.h +++ b/src/plugins/accel/accel_sensor_hal.h @@ -61,8 +61,6 @@ private: bool m_sensorhub_controlled; - cmutex m_value_mutex; - bool update_value_input_event(void); bool update_value_iio(void); };