@@ -22,13 +22,13 @@ public class BusyWaitQueue : IDedicatedConsumerThreadWork
22
22
private List < Action > _actions = new List < Action > ( ) ;
23
23
private List < Action > _toPass = new List < Action > ( ) ;
24
24
25
- ///<summary>
25
+ /// <summary>
26
26
/// BusyWaitQueue with custom executor.
27
- ///</summary>
28
- ///<param name="spinsBeforeTimeCheck"></param>
29
- ///<param name="msBeforeBlockingWait"></param>
30
- ///<param name="executorBatch"></param>
31
- ///<param name="executorSingle"></param>
27
+ /// </summary>
28
+ /// <param name="spinsBeforeTimeCheck"></param>
29
+ /// <param name="msBeforeBlockingWait"></param>
30
+ /// <param name="executorBatch"></param>
31
+ /// <param name="executorSingle">The executor for each operation. </param>
32
32
public BusyWaitQueue ( int spinsBeforeTimeCheck , int msBeforeBlockingWait , IExecutorBatch executorBatch , IExecutor executorSingle )
33
33
{
34
34
_executorBatch = executorBatch ;
@@ -51,10 +51,21 @@ public BusyWaitQueue(int spinsBeforeTimeCheck, int msBeforeBlockingWait)
51
51
/// <param name="action"></param>
52
52
public void Enqueue ( Action action )
53
53
{
54
- lock ( _lock )
54
+ if ( _executorSingle != null )
55
55
{
56
- _actions . Add ( action ) ;
57
- Monitor . PulseAll ( _lock ) ;
56
+ lock ( _lock )
57
+ {
58
+ _actions . Add ( ( ) => _executorSingle . Execute ( action ) ) ;
59
+ Monitor . PulseAll ( _lock ) ;
60
+ }
61
+ }
62
+ else
63
+ {
64
+ lock ( _lock )
65
+ {
66
+ _actions . Add ( action ) ;
67
+ Monitor . PulseAll ( _lock ) ;
68
+ }
58
69
}
59
70
}
60
71
@@ -147,7 +158,7 @@ private bool ExecuteNextBatch()
147
158
{
148
159
return false ;
149
160
}
150
- _executorBatch . Execute ( toExecute , _executorSingle ) ;
161
+ _executorBatch . Execute ( toExecute ) ;
151
162
return true ;
152
163
}
153
164
}
0 commit comments