@@ -16,9 +16,9 @@ namespace Castle.MicroKernel.Lifestyle.Pool
16
16
{
17
17
using System ;
18
18
using System . Collections . Generic ;
19
+ using System . Threading ;
19
20
20
21
using Castle . Core ;
21
- using Castle . Core . Internal ;
22
22
using Castle . MicroKernel . Context ;
23
23
24
24
[ Serializable ]
@@ -29,7 +29,7 @@ public class DefaultPool : IPool, IDisposable
29
29
private readonly Dictionary < object , Burden > inUse = new Dictionary < object , Burden > ( ) ;
30
30
private readonly int initialSize ;
31
31
private readonly int maxsize ;
32
- private readonly Lock rwlock = Lock . Create ( ) ;
32
+ private readonly ReaderWriterLockSlim rwlock = new ReaderWriterLockSlim ( ) ;
33
33
private bool initialized ;
34
34
35
35
public DefaultPool ( int initialSize , int maxsize , IComponentActivator componentActivator )
@@ -54,7 +54,8 @@ public virtual void Dispose()
54
54
55
55
public virtual bool Release ( object instance )
56
56
{
57
- using ( rwlock . ForWriting ( ) )
57
+ rwlock . EnterWriteLock ( ) ;
58
+ try
58
59
{
59
60
Burden burden ;
60
61
@@ -85,6 +86,10 @@ public virtual bool Release(object instance)
85
86
}
86
87
}
87
88
}
89
+ finally
90
+ {
91
+ rwlock . ExitWriteLock ( ) ;
92
+ }
88
93
89
94
// Pool is full or has been disposed.
90
95
@@ -95,7 +100,8 @@ public virtual bool Release(object instance)
95
100
public virtual object Request ( CreationContext context , Func < CreationContext , Burden > creationCallback )
96
101
{
97
102
Burden burden ;
98
- using ( rwlock . ForWriting ( ) )
103
+ rwlock . EnterWriteLock ( ) ;
104
+ try
99
105
{
100
106
if ( ! initialized )
101
107
{
@@ -124,6 +130,10 @@ public virtual object Request(CreationContext context, Func<CreationContext, Bur
124
130
throw new PoolException ( "burden returned by creationCallback does not have root instance associated with it (its Instance property is null)." ) ;
125
131
}
126
132
}
133
+ finally
134
+ {
135
+ rwlock . ExitWriteLock ( ) ;
136
+ }
127
137
return burden . Instance ;
128
138
}
129
139
0 commit comments