Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit a08d01d

Browse files
Remove internal Lock/Reader/Writer structs.
1 parent b50ddae commit a08d01d

File tree

5 files changed

+39
-125
lines changed

5 files changed

+39
-125
lines changed

src/System.Composition.Convention/src/Microsoft/Internal/Lock.Reader.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/System.Composition.Convention/src/Microsoft/Internal/Lock.Writer.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/System.Composition.Convention/src/Microsoft/Internal/Lock.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/System.Composition.Convention/src/System.Composition.Convention.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
<Compile Include="Microsoft\Composition\Diagnostics\TraceSourceTraceWriter.cs" />
4444
<Compile Include="Microsoft\Composition\Diagnostics\TraceWriter.cs" />
4545
<Compile Include="Microsoft\Internal\AttributeServices.cs" />
46-
<Compile Include="Microsoft\Internal\Lock.cs" />
47-
<Compile Include="Microsoft\Internal\Lock.Reader.cs" />
48-
<Compile Include="Microsoft\Internal\Lock.Writer.cs" />
4946
<Compile Include="Microsoft\Internal\ReflectionServices.cs" />
5047
<Compile Include="Strings.Designer.cs" />
5148
<Compile Include="System\Composition\Convention\ConventionBuilder.cs" />

src/System.Composition.Convention/src/System/Composition/Convention/ConventionBuilder.cs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
5+
using Microsoft.Internal;
66
using System.Collections.Generic;
77
using System.Linq;
8-
using System.Text;
98
using System.Reflection;
10-
11-
using Microsoft.Internal;
9+
using System.Threading;
1210

1311
namespace System.Composition.Convention
1412
{
@@ -19,7 +17,7 @@ public class ConventionBuilder : AttributedModelProvider
1917
{
2018
private static readonly List<object> s_emptyList = new List<object>();
2119

22-
private readonly Lock _lock = new Lock();
20+
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
2321
private readonly List<PartConventionBuilder> _conventions = new List<PartConventionBuilder>();
2422

2523
private readonly Dictionary<MemberInfo, List<Attribute>> _memberInfos = new Dictionary<MemberInfo, List<Attribute>>();
@@ -161,13 +159,19 @@ public override IEnumerable<Attribute> GetCustomAttributes(Type reflectedType, S
161159
if (typeInfo != null)
162160
{
163161
var memberInfo = typeInfo as MemberInfo;
164-
using (new ReadLock(_lock))
162+
_lock.EnterReadLock();
163+
try
165164
{
166165
_memberInfos.TryGetValue(memberInfo, out cachedAttributes);
167166
}
167+
finally
168+
{
169+
_lock.ExitReadLock();
170+
}
168171
if (cachedAttributes == null)
169172
{
170-
using (new WriteLock(_lock))
173+
_lock.EnterWriteLock();
174+
try
171175
{
172176
//Double check locking another thread may have inserted one while we were away.
173177
if (!_memberInfos.TryGetValue(memberInfo, out cachedAttributes))
@@ -210,6 +214,10 @@ public override IEnumerable<Attribute> GetCustomAttributes(Type reflectedType, S
210214
// We will have updated all of the MemberInfos by now so lets reload cachedAttributes wiuth the current store
211215
_memberInfos.TryGetValue(memberInfo, out cachedAttributes);
212216
}
217+
finally
218+
{
219+
_lock.ExitWriteLock();
220+
}
213221
}
214222
}
215223
else if (member.IsMemberInfoForProperty() || member.IsMemberInfoForConstructor() || member.IsMemberInfoForMethod())
@@ -232,7 +240,8 @@ private List<Attribute> ReadMemberCustomAttributes(Type reflectedType, System.Re
232240
bool getMemberAttributes = false;
233241

234242
// Now edit the attributes returned from the base type
235-
using (new ReadLock(_lock))
243+
_lock.EnterReadLock();
244+
try
236245
{
237246
if (!_memberInfos.TryGetValue(member, out cachedAttributes))
238247
{
@@ -247,16 +256,25 @@ private List<Attribute> ReadMemberCustomAttributes(Type reflectedType, System.Re
247256
cachedAttributes = null;
248257
}
249258
}
259+
finally
260+
{
261+
_lock.ExitReadLock();
262+
}
250263

251264
if (getMemberAttributes)
252265
{
253266
GetCustomAttributes(null, reflectedType.GetTypeInfo() as MemberInfo);
254267

255268
// We should have run the rules for the enclosing parameter so we can again
256-
using (new ReadLock(_lock))
269+
_lock.EnterReadLock();
270+
try
257271
{
258272
_memberInfos.TryGetValue(member, out cachedAttributes);
259273
}
274+
finally
275+
{
276+
_lock.ExitReadLock();
277+
}
260278
}
261279

262280
return cachedAttributes;
@@ -283,7 +301,8 @@ private List<Attribute> ReadParameterCustomAttributes(Type reflectedType, System
283301
bool getMemberAttributes = false;
284302

285303
// Now edit the attributes returned from the base type
286-
using (new ReadLock(_lock))
304+
_lock.EnterReadLock();
305+
try
287306
{
288307
if (!_parameters.TryGetValue(parameter, out cachedAttributes))
289308
{
@@ -298,16 +317,25 @@ private List<Attribute> ReadParameterCustomAttributes(Type reflectedType, System
298317
cachedAttributes = null;
299318
}
300319
}
320+
finally
321+
{
322+
_lock.ExitReadLock();
323+
}
301324

302325
if (getMemberAttributes)
303326
{
304327
GetCustomAttributes(null, reflectedType.GetTypeInfo() as MemberInfo);
305328

306329
// We should have run the rules for the enclosing parameter so we can again
307-
using (new ReadLock(_lock))
330+
_lock.EnterReadLock();
331+
try
308332
{
309333
_parameters.TryGetValue(parameter, out cachedAttributes);
310334
}
335+
finally
336+
{
337+
_lock.ExitReadLock();
338+
}
311339
}
312340

313341
return cachedAttributes;

0 commit comments

Comments
 (0)