#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"
#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>
#include "message.h"
#include "event_loop.h"
#include "channel_handler.h"
-#include "cmutex.h"
+#include "lock.h"
namespace ipc {
+++ /dev/null
-/*
- * 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();
-}
+++ /dev/null
-/*
- * 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_ */
#include <map>
#include "event_handler.h"
-#include "cmutex.h"
+#include "lock.h"
namespace ipc {
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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_ */