Beispiel #1
0
        internal static IOThread Create()
        {
            IOThread thread = new IOThread();

            threads.Add(thread);
            return(thread);
        }
Beispiel #2
0
 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());
     }
 }
Beispiel #3
0
        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));
        }
Beispiel #4
0
 private static void OnThreadEnd(IOThread t)
 {
     lock (_threadModifyLock) _threads.Remove(t);
 }
Beispiel #5
0
 public void WrapperBind()
 => (BoundThread = IOControl.GetBest()).Enqueue(new IOOperation()
 {
     Callee = this,
     Type   = OperationType.WrapperBind,
 });
Beispiel #6
0
 internal static bool Remove(IOThread thread)
 {
     lock (m_lock) return(threads.Remove(thread));
 }