HikariThreading.ThreadManager.UnsafeHandleThreads C# (CSharp) Method

UnsafeHandleThreads() private method

Assigns work and removed napping Task from their threads.
private UnsafeHandleThreads ( ) : void
return void
        private void UnsafeHandleThreads( )
        {
            List<Thread> bored_threads = new List<Thread>();

            // Get our bored and napping threads
            lock ( threadLock )
            {
                foreach ( Thread thread in threads )
                {
                    if ( !thread.Running )
                        bored_threads.Add(thread);
                    else if ( thread.Napping )
                    {
                        bored_threads.Add(thread);
                        napping.Add(thread.PullNapper());
                    }
                }
            }

            int num_bored = bored_threads.Count;
            // Give em work
            foreach ( Thread thread in bored_threads )
            {
                ITask task;

                // Grab the Task inside the lock so we don't fuck up,
                // then start the task outside in case the... actually I dunno why.
                // Thought I might have a perma lock from that but its on a
                // different thread.
                lock ( workLock )
                {
                    // If we're outta work, stop
                    if ( waiting.Count <= 0 )
                        break;
                    task = waiting.Dequeue();
                    waitingSpawns.Dequeue();
                }

                thread.StartTask(task);
                num_bored--;
            }

            if ( num_bored == 0 )
                lastNoBoredThreads = DateTime.Now;
        }