internal static IOThread Create() { IOThread thread = new IOThread(); threads.Add(thread); return(thread); }
internal static IOThread GetBest() { lock (m_lock) { IOThread best = null; for (int i = 0; i < threads.Count; i++) { if (threads[i].Closing) { continue; } if (threads[i].OperationCount >= OperationsPerThread) { continue; } if (threads[i].SocketCount >= SocketsPerThread) { continue; } if (best == null || best.SocketCount < threads[i].SocketCount) { best = threads[i]; } } return(best ?? Create()); } }
public static IOThread Enqueue(TcpSocket socket) { IOThread best = null; lock (_threadModifyLock) { for (int i = 0; i < _threads.Count; i++) { IOThread curr = _threads[i]; if (best == null || best.SocketCount > curr.SocketCount) { best = curr; } } if (best == null || best.SocketCount > THREAD_MAX_SOCKETS) { IOThread empty = new IOThread(); _threads.Add(empty); best = empty; } } return(best.EnqueueNew(socket)); }
private static void OnThreadEnd(IOThread t) { lock (_threadModifyLock) _threads.Remove(t); }
public void WrapperBind() => (BoundThread = IOControl.GetBest()).Enqueue(new IOOperation() { Callee = this, Type = OperationType.WrapperBind, });
internal static bool Remove(IOThread thread) { lock (m_lock) return(threads.Remove(thread)); }