private void outputWorker() { List <byte> dataToSend = new List <byte>(); socket.NoDelay = true; while (ShouldBeRunning && socket.Connected) { Thread.Sleep(1); dataToSend.Clear(); while (DataToSendQueue.Count > 0) { dataToSend.AddRange(DataToSendQueue.Dequeue()); } if (dataToSend.Count == 0) { continue; } try { //Send ALL bytes at once instead of "per packet", should be better int r = socket.Send(dataToSend.ToArray()); } catch (Exception E) { Debug.WriteLine(E.StackTrace); } } }
private void inputWorker() { while (ShouldBeRunning) { while (InputQueue.Count > 0) { ProcessInputPacket(InputQueue.Dequeue()); } Thread.Sleep(1); } }
/// <summary> /// [AI thread] Retrieves the last parameters sent to the AI thread. /// </summary> /// <returns></returns> public static AI_Params Get() { AI_Params p; ThreadSignal.WaitOne(); // Waiting for a Send() call lock (ThreadQueue) { p = ThreadQueue.Dequeue(); } if (ThreadQueue.Count == 0) { ThreadSignal.Reset(); // Going to sleep if nothing else in the queue } return(p); }
private void CheckQueue() { lock (checklock) { while (_queue.Count > 0 && _threads.Count < ThreadsMaxCount) { StartThread(_queue.Dequeue()); } if (_queue.Count == 0 && _threads.Count == 0 && RaiseCompleteEventIfQueueEmpty) { OnCompleted(); } } }
/// <summary> /// メインスレッドでの処理 /// </summary> private void Update() { threadQueue.Commit(); var queue = threadQueue.Dequeue(); foreach (var q in queue) { try { q.Invoke(); } catch (Exception ex) { Debug.LogError(ex); } } }
/// <summary> /// Run the first thread in the ThreadQueue /// </summary> private void RunThread(bool nullifyThreadInst = false) { ThreadQueue.Peek().IsBackground = true; ThreadQueue.Peek().Start(); runningThreads++; if (runningThreads >= 3) { ThreadQueue.Peek().Join(); runningThreads--; } ThreadingEventArgs removeArgs = new ThreadingEventArgs(); removeArgs.Thread = ThreadQueue.Peek(); ThreadQueue.Dequeue(); ItemRemovedFromThreadQueue(removeArgs); }
private void inputWorker() { int count = 0; // Using this since its possible one can get added to the queue while another is being processed while (ShouldBeRunning) { while (InputQueue.myCount > 0) { ProcessInputPacket(InputQueue.Dequeue()); count++; } if (count > 0) { //Counter.AddTick("pps_in", maxThisSecond); //Counter.AddTick("average_pps_in", Counter.GetAverageValue("pps_in")); } Thread.Sleep(1); } }
internal void ScheduleNextThread() { Thread t = readyQueue.Dequeue(); if (t == null) { if (collectionRequested) { CompilerIntrinsics.Cli(); // TODO: superfluous NucleusCalls.DebugPrintHex(70, ++gcCount); NucleusCalls.DebugPrintHex(60, 0); long t1 = NucleusCalls.Rdtsc(); // No ready threads. // Make anyone waiting for GC ready: while (true) { t = collectionQueue.Dequeue(); if (t == null) { break; } readyQueue.Enqueue(t); } t = readyQueue.Dequeue(); // Garbage collect, then we're ready to go. CompilerIntrinsics.Sti(); System.DebugStub.Print("GarbageCollecting. "); CompilerIntrinsics.Cli(); NucleusCalls.GarbageCollect(); collectionRequested = false; long t2 = NucleusCalls.Rdtsc(); uint diff = (uint)((t2 - t1) >> 10); NucleusCalls.DebugPrintHex(60, diff); } while (t == null) { // TODO: let the CPU sleep here // TODO: enable interrupts CompilerIntrinsics.Cli(); // TODO: superfluous if (!CheckWakeUp()) { // No threads to run. The system is finished. CompilerIntrinsics.Cli(); // TODO: superfluous NucleusCalls.DebugPrintHex(0, 0x76543210); while (true) { } } t = readyQueue.Dequeue(); CompilerIntrinsics.Cli(); // TODO: superfluous } } // Go to t. RunThread(t); // We're back. Somebody (not necessarily t) yielded to us. }