File tree Expand file tree Collapse file tree 2 files changed +17
-17
lines changed
projects/RabbitMQ.Client/client/impl Expand file tree Collapse file tree 2 files changed +17
-17
lines changed Original file line number Diff line number Diff line change @@ -8,27 +8,19 @@ namespace RabbitMQ.Client.Impl
8
8
{
9
9
internal sealed class AsyncConsumerWorkService : ConsumerWorkService
10
10
{
11
- private readonly ConcurrentDictionary < IModel , WorkPool > _workPools ;
12
- private readonly Func < IModel , WorkPool > _startNewWorkPoolFunc ;
13
-
14
- public AsyncConsumerWorkService ( )
15
- {
16
- _workPools = new ConcurrentDictionary < IModel , WorkPool > ( ) ;
17
- _startNewWorkPoolFunc = model => StartNewWorkPool ( model ) ;
18
- }
11
+ private readonly ConcurrentDictionary < IModel , WorkPool > _workPools = new ConcurrentDictionary < IModel , WorkPool > ( ) ;
12
+ private readonly Func < IModel , WorkPool > _startNewWorkPoolFunc = model => StartNewWorkPool ( model ) ;
19
13
20
14
public void Schedule < TWork > ( ModelBase model , TWork work ) where TWork : Work
21
15
{
22
16
/*
23
17
* rabbitmq/rabbitmq-dotnet-client#841
24
18
* https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2.getoradd
25
- *
26
- * The lock is necessary because calling the value delegate is not atomic .
19
+ * Note that the value delegate is not atomic but instances of this class are not meant to be used by
20
+ * multiple threads .
27
21
*/
28
- lock ( _workPools )
29
- {
30
- _workPools . GetOrAdd ( model , _startNewWorkPoolFunc ) . Enqueue ( work ) ;
31
- }
22
+ WorkPool workPool = _workPools . GetOrAdd ( model , _startNewWorkPoolFunc ) ;
23
+ workPool . Enqueue ( work ) ;
32
24
}
33
25
34
26
private static WorkPool StartNewWorkPool ( IModel model )
Original file line number Diff line number Diff line change 5
5
6
6
namespace RabbitMQ . Client . Impl
7
7
{
8
- class ConsumerWorkService
8
+ internal class ConsumerWorkService
9
9
{
10
10
private readonly ConcurrentDictionary < IModel , WorkPool > _workPools = new ConcurrentDictionary < IModel , WorkPool > ( ) ;
11
+ private readonly Func < IModel , WorkPool > _startNewWorkPoolFunc = model => StartNewWorkPool ( model ) ;
11
12
12
13
public void AddWork ( IModel model , Action fn )
13
14
{
14
- _workPools . GetOrAdd ( model , StartNewWorkPool ) . Enqueue ( fn ) ;
15
+ /*
16
+ * rabbitmq/rabbitmq-dotnet-client#841
17
+ * https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2.getoradd
18
+ * Note that the value delegate is not atomic but instances of this class are not meant to be used by
19
+ * multiple threads.
20
+ */
21
+ WorkPool workPool = _workPools . GetOrAdd ( model , _startNewWorkPoolFunc ) ;
22
+ workPool . Enqueue ( fn ) ;
15
23
}
16
24
17
- private WorkPool StartNewWorkPool ( IModel model )
25
+ private static WorkPool StartNewWorkPool ( IModel model )
18
26
{
19
27
var newWorkPool = new WorkPool ( ) ;
20
28
newWorkPool . Start ( ) ;
You can’t perform that action at this time.
0 commit comments