From d2548bd91c67a10ae1fe210d735255d350e6a06b Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 20 Oct 2014 14:10:51 +0200 Subject: [PATCH] Lock guard: deprecate --- src/stats.cpp | 1 - src/utils/lock_guard.h | 4 ++++ src/utils/video_frame_pool.h | 1 - src/utils/wait_obj.h | 30 +++++++++++++----------------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/stats.cpp b/src/stats.cpp index ee6041f93..962112917 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -8,7 +8,6 @@ #include "debug.h" #include "messaging.h" #include "module.h" -#include "utils/lock_guard.h" #include "utils/resource_manager.h" #define MAX_ITEMS 100 diff --git a/src/utils/lock_guard.h b/src/utils/lock_guard.h index 93892dde3..1ff97dfa1 100644 --- a/src/utils/lock_guard.h +++ b/src/utils/lock_guard.h @@ -1,3 +1,7 @@ +/** + * @deprecated + * Do not use these functions in new code, use rather std::lock_guard and similar + */ #ifndef LOCK_GUARD_H_ #define LOCK_GUARD_H_ diff --git a/src/utils/video_frame_pool.h b/src/utils/video_frame_pool.h index 624b7b7b6..27d5375ed 100644 --- a/src/utils/video_frame_pool.h +++ b/src/utils/video_frame_pool.h @@ -47,7 +47,6 @@ #include "video.h" #ifdef __cplusplus -#include "utils/lock_guard.h" #include #include diff --git a/src/utils/wait_obj.h b/src/utils/wait_obj.h index 4375061f5..95ab8310b 100644 --- a/src/utils/wait_obj.h +++ b/src/utils/wait_obj.h @@ -39,34 +39,30 @@ #define UTILS_WAIT_OBJ_H_ #ifdef __cplusplus -#include "utils/lock_guard.h" +#include +#include + struct wait_obj { public: wait_obj() : m_val(false) { - pthread_mutex_init(&m_lock, NULL); - pthread_cond_init(&m_cv, NULL); - } - ~wait_obj() { - pthread_mutex_destroy(&m_lock); - pthread_cond_destroy(&m_cv); } void wait() { - lock_guard guard(m_lock); - while (!m_val) - pthread_cond_wait(&m_cv, &m_lock); + std::unique_lock lk(m_lock); + m_cv.wait(lk, [this] { return m_val; }); } void reset() { - lock_guard guard(m_lock); - m_val = false; + std::lock_guard lk(m_lock); + m_val = false; } void notify() { - lock_guard guard(m_lock); - m_val = true; - pthread_cond_signal(&m_cv); + std::unique_lock lk(m_lock); + m_val = true; + lk.unlock(); + m_cv.notify_one(); } private: - pthread_mutex_t m_lock; - pthread_cond_t m_cv; + std::mutex m_lock; + std::condition_variable m_cv; bool m_val; }; #endif // __cplusplus