directdispatcher.cs
来自「破解的飞信源代码」· CS 代码 · 共 71 行
CS
71 行
namespace NCindy.Session.Dispatcher
{
using NCindy;
using System;
using System.Collections;
using System.Threading;
public class DirectDispatcher : IDispatcher
{
private static readonly LocalDataStoreSlot local = Thread.AllocateDataSlot();
public static readonly int NumberOfProcessors = Environment.get_ProcessorCount();
protected Thread[] workers;
public DirectDispatcher() : this(GetDefaultThreadsCount())
{
}
public DirectDispatcher(int workerThreadsCount)
{
}
public void Block()
{
}
public void Dispatch(ISession session, SessionEventDispatcher eventObject)
{
Queue threadLocalQueue = GetThreadLocalQueue();
threadLocalQueue.Enqueue(eventObject);
if (threadLocalQueue.Count <= 1)
{
eventObject();
threadLocalQueue.Dequeue();
while (threadLocalQueue.Count > 0)
{
SessionEventDispatcher dispatcher = (SessionEventDispatcher) threadLocalQueue.Dequeue();
if (dispatcher != null)
{
dispatcher();
}
}
}
}
protected void DispatchLoop()
{
}
protected static int GetDefaultThreadsCount()
{
if (NumberOfProcessors < 2)
{
return 2;
}
return NumberOfProcessors;
}
private static Queue GetThreadLocalQueue()
{
Queue data = (Queue) Thread.GetData(local);
if (data == null)
{
data = new Queue();
Thread.SetData(local, data);
}
return data;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?