private void wakeThreads ( int count ) { while ( true ) { int taskCount = Math . max ( 0 , _taskCount . get ( ) ) ; int spinIdleCount = _spinIdleCount . get ( ) ; long threadWakeHead = _threadWakeHead . get ( ) ; long threadWakeTail = _threadWakeTail . get ( ) ; long threadCount = spinIdleCount + threadWakeHead - threadWakeTail ; if ( taskCount <= threadCount ) { return ; } if ( count <= threadCount ) { return ; } ThreadAmp thread = _idleThreadRing . poll ( ) ; if ( thread == null ) { return ; } if ( _threadWakeHead . compareAndSet ( threadWakeHead , threadWakeHead + 1 ) ) { thread . setWakeThread ( ) ; LockSupport . unpark ( thread ) ; } else { // avoid duplicate wake _idleThreadRing . offer ( thread ) ; } } }
wake enough threads to process the tasks