Change filename "cmutex.h" to "lock.h" 91/277991/1
authorTaeminYeom <taemin.yeom@samsung.com>
Mon, 18 Jul 2022 00:46:38 +0000 (09:46 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Mon, 18 Jul 2022 00:46:38 +0000 (09:46 +0900)
Change-Id: I42689942d5b220244dffab30557d2ac2055b590d
Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
src/api/sensor-internal.cpp
src/api/sensor_listener.h
src/shared/channel.h
src/shared/cmutex.cpp [deleted file]
src/shared/cmutex.h [deleted file]
src/shared/event_loop.h
src/shared/lock.cpp [new file with mode: 0644]
src/shared/lock.h [new file with mode: 0644]

index 35b20b5bb0a41fc8d922c28b696c90ad0fe2ed68..77d3c5841657dc04aea74dce9635b026c53e85e4 100644 (file)
@@ -26,7 +26,7 @@
 #include <sensor_listener.h>
 #include <sensor_provider_internal.h>
 #include <sensor-log-private.h>
-#include <cmutex.h>
+#include <lock.h>
 #include <command_types.h>
 #include "sensor_reader.h"
 
index f6543539bb69c1bb5604827ed1721d9c0a40922c..eeb8065352a88aa29944a68a0f3328dee3540a0b 100644 (file)
@@ -25,7 +25,7 @@
 #include <event_loop.h>
 #include <sensor_info.h>
 #include <sensor-types-private.h>
-#include <cmutex.h>
+#include <lock.h>
 #include <map>
 #include <atomic>
 #include <vector>
index dec1149f7c255bddd8ab4d636f3933ffb0b5bf12..32a200c7cdd605788477fc59b54f6db82f27faad 100644 (file)
@@ -28,7 +28,7 @@
 #include "message.h"
 #include "event_loop.h"
 #include "channel_handler.h"
-#include "cmutex.h"
+#include "lock.h"
 
 namespace ipc {
 
diff --git a/src/shared/cmutex.cpp b/src/shared/cmutex.cpp
deleted file mode 100644 (file)
index c29aa72..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 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 <pthread.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <cmutex.h>
-#include <sensor-log-private.h>
-
-using namespace sensor;
-
-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(void)
-{
-#ifdef _LOCK_DEBUG
-       lock("mutex", __MODULE__, __func__, __LINE__);
-#else
-       lock_impl();
-#endif
-}
-
-void cmutex::lock(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);
-
-       ret = try_lock_impl();
-
-       if (ret == 0) {
-               pthread_mutex_lock(&m_mutex);
-               snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
-               pthread_mutex_unlock(&m_mutex);
-               return;
-       }
-
-       gettimeofday(&sv, NULL);
-       lock_waiting_start_time = MICROSECONDS(sv);
-
-       pthread_mutex_lock(&m_mutex);
-       _I("%s is waiting for getting %s(%p) owned in %s",
-               m_curent_info, expr, this, m_owner_info);
-       pthread_mutex_unlock(&m_mutex);
-
-       lock_impl();
-
-       gettimeofday(&sv, NULL);
-       lock_acquired_time = MICROSECONDS(sv);
-
-       waiting_time = lock_acquired_time - lock_waiting_start_time;
-
-       pthread_mutex_lock(&m_mutex);
-       _I("%s acquires lock after waiting %lluus, %s(%p) 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_mutex);
-}
-
-void cmutex::unlock(void)
-{
-       unlock_impl();
-}
-
-int cmutex::try_lock(void)
-{
-       return try_lock_impl();
-}
-
-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(void)
-{
-       return pthread_mutex_unlock(&m_mutex);
-}
-
-Autolock::Autolock(cmutex &m, const char* expr, const char *module, const char *func, int line)
-: m_lock(m)
-{
-       m_lock.lock(expr, module, func, line);
-}
-
-Autolock::Autolock(cmutex &m)
-: m_lock(m)
-{
-       m_lock.lock();
-}
-
-Autolock::~Autolock()
-{
-       m_lock.unlock();
-}
diff --git a/src/shared/cmutex.h b/src/shared/cmutex.h
deleted file mode 100644 (file)
index 91219a0..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 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.
- *
- */
-
-#ifndef _CMUTEX_H_
-#define _CMUTEX_H_
-
-#include <pthread.h>
-
-namespace sensor {
-
-#ifndef MICROSECONDS
-#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec)
-#endif
-
-#ifdef _LOCK_DEBUG
-#define AUTOLOCK(x)      Autolock x##_autolock((x), #x, __MODULE__, __func__, __LINE__)
-#define LOCK(x)          (x).lock(#x, __MODULE__, __func__, __LINE__)
-#define UNLOCK(x)        (x).unlock()
-#else
-#define AUTOLOCK(x)      Autolock x##_autolock((x))
-#define LOCK(x)          (x).lock()
-#define UNLOCK(x)        (x).unlock()
-#endif
-
-class cmutex {
-public:
-       cmutex();
-       virtual ~cmutex();
-
-       void lock(void);
-       void lock(const char* expr, const char *module, const char *func, int line);
-       void unlock(void);
-       int try_lock(void);
-
-protected:
-       int lock_impl(void);
-       int try_lock_impl(void);
-       int unlock_impl(void);
-
-private:
-       pthread_mutex_t m_mutex;
-       static const int OWNER_INFO_LEN = 256;
-       char m_owner_info[OWNER_INFO_LEN];
-};
-
-class Autolock {
-private:
-       cmutex& m_lock;
-public:
-       Autolock(cmutex &m, const char* expr, const char *module, const char *func, int line);
-       Autolock(cmutex &m);
-       ~Autolock();
-};
-
-}
-#endif /* _CMUTEX_H_ */
index aeae959c36f1ea89d358504155be8728fe0decd0..6e560ff0ac874cf5971d2d3bbb4dea52fadf1611 100644 (file)
@@ -26,7 +26,7 @@
 #include <map>
 
 #include "event_handler.h"
-#include "cmutex.h"
+#include "lock.h"
 
 namespace ipc {
 
diff --git a/src/shared/lock.cpp b/src/shared/lock.cpp
new file mode 100644 (file)
index 0000000..650e5c7
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2013 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 <pthread.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <lock.h>
+#include <sensor-log-private.h>
+
+using namespace sensor;
+
+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(void)
+{
+#ifdef _LOCK_DEBUG
+       lock("mutex", __MODULE__, __func__, __LINE__);
+#else
+       lock_impl();
+#endif
+}
+
+void cmutex::lock(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);
+
+       ret = try_lock_impl();
+
+       if (ret == 0) {
+               pthread_mutex_lock(&m_mutex);
+               snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
+               pthread_mutex_unlock(&m_mutex);
+               return;
+       }
+
+       gettimeofday(&sv, NULL);
+       lock_waiting_start_time = MICROSECONDS(sv);
+
+       pthread_mutex_lock(&m_mutex);
+       _I("%s is waiting for getting %s(%p) owned in %s",
+               m_curent_info, expr, this, m_owner_info);
+       pthread_mutex_unlock(&m_mutex);
+
+       lock_impl();
+
+       gettimeofday(&sv, NULL);
+       lock_acquired_time = MICROSECONDS(sv);
+
+       waiting_time = lock_acquired_time - lock_waiting_start_time;
+
+       pthread_mutex_lock(&m_mutex);
+       _I("%s acquires lock after waiting %lluus, %s(%p) 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_mutex);
+}
+
+void cmutex::unlock(void)
+{
+       unlock_impl();
+}
+
+int cmutex::try_lock(void)
+{
+       return try_lock_impl();
+}
+
+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(void)
+{
+       return pthread_mutex_unlock(&m_mutex);
+}
+
+Autolock::Autolock(cmutex &m, const char* expr, const char *module, const char *func, int line)
+: m_lock(m)
+{
+       m_lock.lock(expr, module, func, line);
+}
+
+Autolock::Autolock(cmutex &m)
+: m_lock(m)
+{
+       m_lock.lock();
+}
+
+Autolock::~Autolock()
+{
+       m_lock.unlock();
+}
diff --git a/src/shared/lock.h b/src/shared/lock.h
new file mode 100644 (file)
index 0000000..3961779
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2013 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.
+ *
+ */
+
+#ifndef _LOCK_H_
+#define _LOCK_H_
+
+#include <pthread.h>
+
+namespace sensor {
+
+#ifndef MICROSECONDS
+#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec)
+#endif
+
+#ifdef _LOCK_DEBUG
+#define AUTOLOCK(x)      Autolock x##_autolock((x), #x, __MODULE__, __func__, __LINE__)
+#define LOCK(x)          (x).lock(#x, __MODULE__, __func__, __LINE__)
+#define UNLOCK(x)        (x).unlock()
+#else
+#define AUTOLOCK(x)      Autolock x##_autolock((x))
+#define LOCK(x)          (x).lock()
+#define UNLOCK(x)        (x).unlock()
+#endif
+
+class cmutex {
+public:
+       cmutex();
+       virtual ~cmutex();
+
+       void lock(void);
+       void lock(const char* expr, const char *module, const char *func, int line);
+       void unlock(void);
+       int try_lock(void);
+
+protected:
+       int lock_impl(void);
+       int try_lock_impl(void);
+       int unlock_impl(void);
+
+private:
+       pthread_mutex_t m_mutex;
+       static const int OWNER_INFO_LEN = 256;
+       char m_owner_info[OWNER_INFO_LEN];
+};
+
+class Autolock {
+private:
+       cmutex& m_lock;
+public:
+       Autolock(cmutex &m, const char* expr, const char *module, const char *func, int line);
+       Autolock(cmutex &m);
+       ~Autolock();
+};
+
+}
+#endif /* _LOCK_H_ */