Skip to content

Commit a5af030

Browse files
committed
Do not call pending actions under globally shared lock
Signed-off-by: Viktor Svyatokha <[email protected]>
1 parent 417b221 commit a5af030

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/MySqlConnector/Utilities/TimerQueue.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ private TimerQueue()
6767

6868
private void Callback(object? obj)
6969
{
70+
var actionsToBeCalled = new List<Action>();
71+
7072
lock (m_lock)
7173
{
7274
// process all timers that have expired or will expire in the granularity of a clock tick
7375
while (m_timeoutActions.Count > 0 && unchecked(m_timeoutActions[0].Time - Environment.TickCount) < 15)
7476
{
75-
m_timeoutActions[0].Action();
77+
actionsToBeCalled.Add(m_timeoutActions[0].Action);
7678
m_timeoutActions.RemoveAt(0);
7779
}
7880

@@ -86,6 +88,11 @@ private void Callback(object? obj)
8688
UnsafeSetTimer(delay);
8789
}
8890
}
91+
92+
foreach (var action in actionsToBeCalled)
93+
{
94+
action();
95+
}
8996
}
9097

9198
// Should be called while holding m_lock.

0 commit comments

Comments
 (0)