Utils: Generalize auto-locking mechanisms
This patch makes code ready for other lock types like RW-locks Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit is contained in:
parent
fa27333c0e
commit
39e3a4709c
1 changed files with 15 additions and 11 deletions
|
|
@ -43,25 +43,29 @@ private:
|
|||
CWdmSpinLock& operator= (const CWdmSpinLock&) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class CLockedContext
|
||||
template <typename T, void (T::*LockFunc)(), void (T::*UnlockFunc)()>
|
||||
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<CWdmSpinLock> TSpinLocker;
|
||||
template <typename T>
|
||||
using CLockedContext = CBaseLockedContext <T, &T::Lock, &T::Unlock>;
|
||||
|
||||
class CWdmRefCounter
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue