blob: a8157da5399d6d48bf39c6943d7c266497ec23c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/**************************************************************************
A/V Stream Camera Sample
Copyright (c) 2013, Microsoft Corporation.
File:
Mutex.h
Abstract:
This file provides the declaration of KMutex and KScopedMutex.
KMutex provides a wrapper around a KMUTEX object. KScopedMutex is
provided as a helper class to ensure all exits release the lock.
History:
created 7/16/2013
**************************************************************************/
#pragma once
//
// Specialized class for KMUTEX
//
class KMutex : CNonCopyable
{
KMUTEX m_Lock;
public:
KMutex()
{
KeInitializeMutex( &m_Lock, 0 );
}
virtual ~KMutex();
//
// Preferred lock method.
//
_IRQL_requires_min_(PASSIVE_LEVEL)
_When_((Timeout==NULL || Timeout->QuadPart!=0), _IRQL_requires_max_(APC_LEVEL))
_When_((Timeout!=NULL &&Timeout->QuadPart==0), _IRQL_requires_max_(DISPATCH_LEVEL))
NTSTATUS
Lock(
_In_opt_ PLARGE_INTEGER Timeout=nullptr
);
//
// Preferred unlock method.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
void
Unlock();
};
//
// Use this class to hold a spinlock through a particular scope
//
class KScopedMutex : CNonCopyable
{
KMutex &m_Lock;
public:
_IRQL_requires_min_(PASSIVE_LEVEL)
_IRQL_requires_max_(APC_LEVEL)
KScopedMutex( KMutex &lock )
: m_Lock(lock)
{
m_Lock.Lock();
}
_IRQL_requires_max_(DISPATCH_LEVEL)
~KScopedMutex(void)
{
m_Lock.Unlock();
}
};
|