Skip to content

Commit

Permalink
Utils: Introduce RW-locks
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
  • Loading branch information
Dmitry Fleytman committed Dec 24, 2015
1 parent 39e3a47 commit b005694
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions UsbDk/UsbDkUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,79 @@ class CBaseLockedContext
template <typename T>
using CLockedContext = CBaseLockedContext <T, &T::Lock, &T::Unlock>;

#if !TARGET_OS_WIN_XP

class CWdmExSpinLock
{
public:
CWdmExSpinLock()
{}

void LockShared()
{
m_OldIrql = ExAcquireSpinLockShared(&m_Lock);
}

void UnlockShared()
{
ExReleaseSpinLockShared(&m_Lock, m_OldIrql);
}

void LockExclusive()
{
m_OldIrql = ExAcquireSpinLockExclusive(&m_Lock);
}

void UnlockExclusive()
{
ExReleaseSpinLockExclusive(&m_Lock, m_OldIrql);
}

private:
EX_SPIN_LOCK m_Lock = {};
KIRQL m_OldIrql;

CWdmExSpinLock(const CWdmExSpinLock&) = delete;
CWdmExSpinLock& operator= (const CWdmExSpinLock&) = delete;
};

#else //!TARGET_OS_WIN_XP

//EX_SPIN_LOCK is not supported on Windows XP so we simulate
//it with usual spinlock.

class CWdmExSpinLock : public CWdmSpinLock
{
public:
void LockShared()
{
Lock();
}

void UnlockShared()
{
Unlock();
}

void LockExclusive()
{
Lock();
}

void UnlockExclusive()
{
Unlock();
}
};

#endif //TARGET_OS_WIN_XP

template <typename T = CWdmExSpinLock>
using CSharedLockedContext = CBaseLockedContext <T, &T::LockShared, &T::UnlockShared>;

template <typename T = CWdmExSpinLock>
using CExclusiveLockedContext = CBaseLockedContext <T, &T::LockExclusive, &T::UnlockExclusive>;

class CWdmRefCounter
{
public:
Expand Down

0 comments on commit b005694

Please sign in to comment.