Methods Summary |
---|
protected static org.gudy.azureus2.core3.util.NonDaemonTaskRunner | getSingleton()
try{
class_mon.enter();
if ( singleton == null ){
singleton = new NonDaemonTaskRunner();
}
return( singleton );
}finally{
class_mon.exit();
}
|
public static java.lang.Object | run(NonDaemonTask target)
return(getSingleton().runSupport( target, false ));
|
public static java.lang.Object | runAsync(NonDaemonTask target)
return(getSingleton().runSupport( target, true ));
|
protected java.lang.Object | runSupport(NonDaemonTask target, boolean async)
// is this a recursive call? if so, run directly
if ( current_thread == Thread.currentThread()){
return( target.run());
}
taskWrapper wrapper = new taskWrapper( target );
try{
tasks_mon.enter();
tasks.push( wrapper );
task_sem.release();
if ( current_thread == null ){
final AESemaphore wait_sem = new AESemaphore("NonDaemonTaskRunnerTask");
current_thread = new AEThread("NonDaemonTaskRunner" )
{
public void
runSupport()
{
wait_sem.release();
// System.out.println( "non daemon starts" );
while(true){
task_sem.reserve(LINGER_PERIOD);
taskWrapper t = null;
try{
tasks_mon.enter();
if ( tasks.isEmpty()){
current_thread = null;
for (int i=0;i<wait_until_idle_list.size();i++){
((AESemaphore)wait_until_idle_list.get(i)).release();
}
wait_until_idle_list.clear();
break;
}else{
t = (taskWrapper)tasks.pop();
}
}finally{
tasks_mon.exit();
}
t.run();
}
// System.out.println( "non daemon ends" );
}
};
current_thread.setDaemon(false);
current_thread.start();
wait_sem.reserve();
}
}finally{
tasks_mon.exit();
}
if ( async ){
return( null );
}
return( wrapper.waitForResult());
|
public static void | waitUntilIdle()
getSingleton().waitUntilIdleSupport();
|
protected void | waitUntilIdleSupport()
AESemaphore sem;
try{
tasks_mon.enter();
if ( current_thread == null ){
return;
}
sem = new AESemaphore("NDTR::idleWaiter");
wait_until_idle_list.add( sem );
}finally{
tasks_mon.exit();
}
sem.reserve();
|