Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

shellext: use critical sections

on 64bit Windows 7 with 64bit explorer, I see reentrant calls to
CShellExt::IsMemberOf, which is not implemented to be called by
more than one thread at the same time.

Changeset 0a4df15f49de

Parent ffcbae25f9a1

by Adrian Buehlmann

Changes to 3 files · Browse files at 0a4df15f49de Showing diff from parent ffcbae25f9a1 Diff from another changeset...

 
42
43
44
 
 
45
46
47
 
42
43
44
45
46
47
48
49
@@ -42,6 +42,8 @@
   STDMETHODIMP CShellExt::IsMemberOf(LPCWSTR pwszPath, DWORD /* dwAttrib */)  { + ThgCriticalSection cs(GetCriticalSection()); +   std::string cval;   if (GetRegistryConfig("EnableOverlays", cval) != 0 && cval == "0")   return S_FALSE;
 
21
22
23
 
 
 
24
25
26
 
36
37
38
39
 
40
41
 
42
 
43
44
45
 
 
 
46
 
47
48
49
 
99
100
101
 
 
 
 
 
 
102
103
 
104
105
106
 
108
109
110
 
111
112
113
 
130
131
132
 
133
134
135
136
137
138
 
139
140
141
 
167
168
169
 
 
170
171
172
 
176
177
178
 
 
179
180
181
182
183
184
 
 
 
 
 
185
186
187
 
228
229
230
 
231
232
233
234
235
236
 
 
237
238
239
 
21
22
23
24
25
26
27
28
29
 
39
40
41
 
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
124
125
126
127
128
129
130
 
147
148
149
150
151
152
153
154
155
156
157
158
159
160
 
186
187
188
189
190
191
192
193
 
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
 
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@@ -21,6 +21,9 @@
   HMENU hSubMenu = 0;   +CRITICAL_SECTION g_critical_section; + +  typedef struct  {   HKEY hRootKey; @@ -36,14 +39,20 @@
 int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)  {   TDEBUG_TRACE("DllMain"); - +   if (dwReason == DLL_PROCESS_ATTACH)   { + TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH");   g_hmodThisDll = hInstance; + ::InitializeCriticalSection(&g_critical_section);   _LoadResources();   }   else if (dwReason == DLL_PROCESS_DETACH) + { + TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH"); + ::DeleteCriticalSection(&g_critical_section);   _UnloadResources(); + }     return 1;  } @@ -99,8 +108,15 @@
  DestroyMenu(hSubMenu);  }   + +LPCRITICAL_SECTION CDllRegSxClassFactory::GetCriticalSection() +{ + return &g_critical_section; +} +  CDllRegSxClassFactory::CDllRegSxClassFactory(TortoiseOLEClass classToMake)  { + ThgCriticalSection cs(GetCriticalSection());   m_cRef = 0L;   g_cRefThisDll++;   myclassToMake = classToMake; @@ -108,6 +124,7 @@
   CDllRegSxClassFactory::~CDllRegSxClassFactory()  { + ThgCriticalSection cs(GetCriticalSection());   g_cRefThisDll--;  }   @@ -130,12 +147,14 @@
 STDMETHODIMP_(ULONG)  CDllRegSxClassFactory::AddRef()  { + ThgCriticalSection cs(GetCriticalSection());   return ++m_cRef;  }    STDMETHODIMP_(ULONG)  CDllRegSxClassFactory::Release()  { + ThgCriticalSection cs(GetCriticalSection());   if (--m_cRef)   return m_cRef;   @@ -167,6 +186,8 @@
 CShellExt::CShellExt(TortoiseOLEClass tortoiseClass)   : m_ppszFileUserClickedOn(0)  { + ThgCriticalSection cs(GetCriticalSection()); +   myTortoiseClass = tortoiseClass;   m_cRef = 0L;   m_pDataObj = NULL; @@ -176,12 +197,19 @@
   CShellExt::~CShellExt()  { + ThgCriticalSection cs(GetCriticalSection()); +   if (m_pDataObj)   m_pDataObj->Release();     g_cRefThisDll--;  }   +LPCRITICAL_SECTION CShellExt::GetCriticalSection() +{ + return &g_critical_section; +} +  STDMETHODIMP  CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv)  { @@ -228,12 +256,15 @@
 STDMETHODIMP_(ULONG)  CShellExt::AddRef()  { + ThgCriticalSection cs(GetCriticalSection());   return ++m_cRef;  }    STDMETHODIMP_(ULONG)  CShellExt::Release()  { + ThgCriticalSection cs(GetCriticalSection()); +   if(--m_cRef)   return m_cRef;  
 
29
30
31
 
 
32
33
34
 
60
61
62
 
 
63
64
65
 
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
29
30
31
32
33
34
35
36
 
62
63
64
65
66
67
68
69
 
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
@@ -29,6 +29,8 @@
  ~CDllRegSxClassFactory();     public: + static LPCRITICAL_SECTION GetCriticalSection(); +   STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);   STDMETHODIMP_(ULONG) AddRef();   STDMETHODIMP_(ULONG) Release(); @@ -60,6 +62,8 @@
  void CShellExt::DoHgtk(const std::string &);     public: + static LPCRITICAL_SECTION GetCriticalSection(); +   CShellExt(TortoiseOLEClass);   ~CShellExt();   @@ -86,4 +90,22 @@
   typedef CShellExt *LPCSHELLEXT;   + +class ThgCriticalSection +{ + LPCRITICAL_SECTION cs_; + +public: + ThgCriticalSection(LPCRITICAL_SECTION cs): cs_(cs) + { + ::EnterCriticalSection(cs_); + } + + ~ThgCriticalSection() + { + ::LeaveCriticalSection(cs_); + } +}; + +  #endif // _SHELL_EXT_H_