From 45602989a0b3861ee7e36c80e1820c5557689734 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 3 Jan 2014 22:03:16 +0100 Subject: [PATCH] [DEV] add interface auto-remove Mutex --- etk/RegExp.h | 1 + etk/os/Mutex.h | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/etk/RegExp.h b/etk/RegExp.h index 39ae922..ddeec42 100644 --- a/etk/RegExp.h +++ b/etk/RegExp.h @@ -1618,6 +1618,7 @@ template class RegExp { */ std::string getRegExDecorated(void) { // TODO : do it... + return ""; } private: /** diff --git a/etk/os/Mutex.h b/etk/os/Mutex.h index 7a815ea..a465fa6 100644 --- a/etk/os/Mutex.h +++ b/etk/os/Mutex.h @@ -52,7 +52,29 @@ namespace etk { */ void unLock(void); }; - + /** + * @brief AutoLock and un-lock when exit fuction. + */ + class AutoLockMutex { + private: + // Keep a reference on the mutex + etk::Mutex &m_protect; + public: + /** + * @brief constructor that automaticly lock the mutex. + * @param[in] _protect Mutex to Lock. + */ + AutoLockMutex(etk::Mutex& _protect) : + m_protect(_protect) { + m_protect.lock(); + } + /** + * @brief Destructor that Auto Unlock mutex when remove. + */ + virtual ~AutoLockMutex(void){ + m_protect.unLock(); + } + }; }; #endif