blob: 95f9bbe48f1f9b05f0bdf350d9f625a1568a6446 (
plain) (
blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
//
// Copyright (c) 1996 Microsoft Corporation
//
//
// SYNC.H -- Header for Classes:
// CSync
//
// History:
// 05/21/96 JosephJ Created
//
//
#ifndef _SYNC_H_
#define _SYNC_H_
///////////////////////////////////////////////////////////////////////////
// CLASS CSync
///////////////////////////////////////////////////////////////////////////
// Controls access to its parent object. Includes a critical section, and
// (TODO) mechanism for waiting until all threads have finished using
// the parent object.
// Sample session (pObj is a ptr to a hypothetical parent, which implements
// methods Load, Unload, OpenSession, CloseSession using the member CSymc
// object):
// pObj->Load("mdmusr.inf");
// hSession = pObj->OpenSession();
// ... do stuff ...
// pObj->CloseSession(hSession);
// hSync = pObj->Unload();
// if (hSync) WaitForSingleObject(hSync, INFINITE);
// CloseHandle(hSync);
class CSync
{
public:
CSync(void) {InitializeCriticalSection(&m_crit);}
~CSync()
{
EnterCriticalSection(&m_crit);
DeleteCriticalSection(&m_crit);
}
//-------------- EnterCrit ------------------
// Claim our critical section
void EnterCrit(void) const
{
EnterCriticalSection((CRITICAL_SECTION *)&m_crit);
}
//-------------- LeaveCrit ------------------
// Release our critical section
void LeaveCrit(void) const
{
LeaveCriticalSection((CRITICAL_SECTION *)&m_crit);
}
#if (TODO)
BOOL BeginLoad(void)
{
}
void EndLoad(void)
{
EnterCrit();
ASSERT (m_eState == CSYNC_LOADING);
m_eState = CSYNC_LOADED;
LeaveCrit();
}
HANDLE BeginUnload(void)
{
HANDLE h=NULL;
EnterCrit();
if (m_eState == CSYNC_LOADED)
{
m_eState = CSYNC_UNLOADING;
}
else
{
fRet = FALSE;
}
LeaveCrit();
return fRet;
}
void EndUnload(void);
HSESSION BeginSession(void)
{
HSESSION hRet = 1;
EnterCrit();
if (m_eState==SYNC_LOADED)
{
m_uRefCount++;
}
else
{
hRet = 0;
}
LeaveCrit();
return hRet;
}
void EndSession(HSESSION hSession)
{
SLINST *pEventList=NULL;
EnterCrit();
ASSERT(hSession==1 && m_uRefCount);
m_uRefCount--;
if (m_eState==SYNC_UNLOADING && m_pEventList)
{
pEventList = m_pEventList;
m_pEventList=NULL;
}
LeaveCrit();
mfn_SignalAndFree(m_pEventList);
}
BOOL AddContext(HSESSION hS)
{
return FALSE;
}
#endif // TODO
private:
CRITICAL_SECTION m_crit;
#if (TODO)
UINT m_uRefCount;
enum {CSYNC_UNLOADED, CSYNC_LOADING, CSYNC_UNLOADING, CSYNC_UNLOADED}
m_eState;
SLIST* pUnloadEventList;
#endif // TODO
};
#endif // _SYNC_H_
|