Commit ea97bbdc authored by Marc Gravell's avatar Marc Gravell

use a weak-ref in the backlog processor, to try to avoid GC collect misses

parent ea543551
...@@ -54,7 +54,10 @@ public PhysicalBridge(ServerEndPoint serverEndPoint, ConnectionType type, int ti ...@@ -54,7 +54,10 @@ public PhysicalBridge(ServerEndPoint serverEndPoint, ConnectionType type, int ti
Name = Format.ToString(serverEndPoint.EndPoint) + "/" + ConnectionType.ToString(); Name = Format.ToString(serverEndPoint.EndPoint) + "/" + ConnectionType.ToString();
TimeoutMilliseconds = timeoutMilliseconds; TimeoutMilliseconds = timeoutMilliseconds;
_singleWriterMutex = new MutexSlim(timeoutMilliseconds: timeoutMilliseconds); _singleWriterMutex = new MutexSlim(timeoutMilliseconds: timeoutMilliseconds);
_weakRefThis = new WeakReference(this);
} }
private readonly WeakReference _weakRefThis;
private readonly int TimeoutMilliseconds; private readonly int TimeoutMilliseconds;
public enum State : byte public enum State : byte
...@@ -741,9 +744,15 @@ private void PushToBacklog(Message message) ...@@ -741,9 +744,15 @@ private void PushToBacklog(Message message)
private void StartBacklogProcessor() private void StartBacklogProcessor()
{ {
var sched = Multiplexer.SocketManager?.SchedulerPool ?? DedicatedThreadPoolPipeScheduler.Default; var sched = Multiplexer.SocketManager?.SchedulerPool ?? DedicatedThreadPoolPipeScheduler.Default;
sched.Schedule(s_ProcessBacklog, this); sched.Schedule(s_ProcessBacklog, _weakRefThis);
} }
static readonly Action<object> s_ProcessBacklog = s => ((PhysicalBridge)s).ProcessBacklog();
static readonly Action<object> s_ProcessBacklog = s =>
{
var wr = (WeakReference)s;
var bridge = wr.Target as PhysicalBridge;
if (bridge != null) bridge.ProcessBacklog();
};
private void ProcessBacklog() private void ProcessBacklog()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment