mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 06:33:34 +02:00
Refactorings zur Nebenläufigkeit
This commit is contained in:
@@ -42,7 +42,8 @@ public final class Options {
|
||||
STOPPED,
|
||||
TERMINATED,
|
||||
IDLE,
|
||||
DELAYED
|
||||
DELAYED,
|
||||
DISPATCHING
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -410,18 +410,21 @@ public class Zeichenmaschine extends Constants {
|
||||
public void windowClosing( WindowEvent e ) {
|
||||
if( running ) {
|
||||
running = false;
|
||||
teardown();
|
||||
cleanup();
|
||||
mainThread.interrupt();
|
||||
//teardown();
|
||||
//cleanup();
|
||||
}
|
||||
// Give the app a minimum amount of time to shut down
|
||||
// then kill it.
|
||||
try {
|
||||
Thread.sleep(5);
|
||||
} catch( InterruptedException ex ) {
|
||||
} finally {
|
||||
quit(true);
|
||||
while( state != Options.AppState.TERMINATED ) {
|
||||
Thread.yield();
|
||||
if( Thread.interrupted() ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Quit
|
||||
quit(true);
|
||||
}
|
||||
});
|
||||
|
||||
// Fenster zusammenbauen, auf dem Bildschirm zentrieren ...
|
||||
@@ -996,7 +999,7 @@ public class Zeichenmaschine extends Constants {
|
||||
|
||||
updateState = Options.AppState.DELAYED;
|
||||
Thread.sleep(ms - sub, (int) (timer % 1000000L));
|
||||
} catch( InterruptedException ex ) {
|
||||
} catch( InterruptedException ignored ) {
|
||||
// Nothing
|
||||
} finally {
|
||||
updateState = oldState;
|
||||
@@ -1198,10 +1201,12 @@ public class Zeichenmaschine extends Constants {
|
||||
}
|
||||
|
||||
/*
|
||||
* Mouse handling
|
||||
* Input handling
|
||||
*/
|
||||
private void enqueueEvent( InputEvent evt ) {
|
||||
if( updateState != Options.AppState.DELAYED ) {
|
||||
eventQueue.add(evt);
|
||||
}
|
||||
|
||||
if( isPaused() || isStopped() ) {
|
||||
dispatchEvents();
|
||||
@@ -1209,7 +1214,7 @@ public class Zeichenmaschine extends Constants {
|
||||
}
|
||||
|
||||
private void dispatchEvents() {
|
||||
synchronized( eventQueue ) {
|
||||
//synchronized( eventQueue ) {
|
||||
while( !eventQueue.isEmpty() ) {
|
||||
InputEvent evt = eventQueue.poll();
|
||||
|
||||
@@ -1230,7 +1235,7 @@ public class Zeichenmaschine extends Constants {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
private void handleKeyEvent( KeyEvent evt ) {
|
||||
@@ -1469,10 +1474,11 @@ public class Zeichenmaschine extends Constants {
|
||||
// Call to draw()
|
||||
updateState = Options.AppState.DRAWING;
|
||||
Zeichenmaschine.this.draw();
|
||||
updateState = Options.AppState.IDLE;
|
||||
updateState = Options.AppState.DISPATCHING;
|
||||
// Send latest input events after finishing draw
|
||||
// since these may also block
|
||||
dispatchEvents();
|
||||
updateState = Options.AppState.IDLE;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1481,6 +1487,11 @@ public class Zeichenmaschine extends Constants {
|
||||
while( updateThreadExecutor.isRunning()
|
||||
&& !updateThreadExecutor.isWaiting() ) {
|
||||
Thread.yield();
|
||||
|
||||
if( Thread.interrupted() ) {
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Display the current buffer content
|
||||
|
||||
Reference in New Issue
Block a user