From 39e3a4709c0a14ffcaefb4621797cc0eb5ee376a Mon Sep 17 00:00:00 2001 From: Dmitry Fleytman Date: Wed, 23 Dec 2015 11:31:12 +0200 Subject: [PATCH] Utils: Generalize auto-locking mechanisms This patch makes code ready for other lock types like RW-locks Signed-off-by: Dmitry Fleytman --- UsbDk/UsbDkUtil.h | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/UsbDk/UsbDkUtil.h b/UsbDk/UsbDkUtil.h index c0f2e0f..cad020a 100644 --- a/UsbDk/UsbDkUtil.h +++ b/UsbDk/UsbDkUtil.h @@ -43,25 +43,29 @@ private: CWdmSpinLock& operator= (const CWdmSpinLock&) = delete; }; -template -class CLockedContext +template +class CBaseLockedContext { public: - CLockedContext(T &LockObject) + CBaseLockedContext(T &LockObject) : m_LockObject(LockObject) - { m_LockObject.Lock(); } + { + (m_LockObject.*LockFunc)(); + } - ~CLockedContext() - { m_LockObject.Unlock(); } + ~CBaseLockedContext() + { + (m_LockObject.*UnlockFunc)(); + } -private: +protected: T &m_LockObject; - - CLockedContext(const CLockedContext&) = delete; - CLockedContext& operator= (const CLockedContext&) = delete; + CBaseLockedContext(const CBaseLockedContext&) = delete; + CBaseLockedContext& operator= (const CBaseLockedContext&) = delete; }; -typedef CLockedContext TSpinLocker; +template +using CLockedContext = CBaseLockedContext ; class CWdmRefCounter {