[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[albireo-dev] Re: resize/relayout problem again
|
> There is still a race condition in it (I got a wrong display once in 40 times)
This should fix the race condition.
Bruno
Index: src/org/eclipse/albireo/core/SwingControl.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.core/src/org/eclipse/albireo/core/SwingControl.java,v
retrieving revision 1.76
diff -c -3 -r1.76 SwingControl.java
*** src/org/eclipse/albireo/core/SwingControl.java 30 Apr 2008 15:45:10 -0000 1.76
--- src/org/eclipse/albireo/core/SwingControl.java 30 Apr 2008 17:44:59 -0000
***************
*** 699,704 ****
--- 699,705 ----
* the specified sizes, and the OR of the preconditions.
*/
class SetAWTSizeQueue implements Runnable {
+ // True while a request is pending.
private boolean pending /* = false */;
// If pending:
// The AWT time of the notification that triggered this request
***************
*** 708,713 ****
--- 709,716 ----
// The size to which the frame shall be resized.
private int width;
private int height;
+ // True while processing the last request (after it was dequeued).
+ private boolean processing /* = false */;
/**
* Creates an empty queue.
*/
***************
*** 726,731 ****
--- 729,740 ----
assert Display.getCurrent() != null; // On SWT event thread
if (verboseSizeLayout)
System.err.println("SWT thread: Preparing to set size: " + width + " x " + height + " for " + swingComponent);
+ // During the processing of a request, lastValidatedAWTTime is
+ // unreliable: it gets incremented to a value past the
+ // currentAWTTime, but this does not mean that we should drop this
+ // request.
+ if (processing)
+ onBehalfAWTTime = null;
boolean wasPending = this.pending;
// Shortcut to avoid posting a Runnable that has no effect.
// (lastValidatedAWTTime can only increase until the Runnable is
***************
*** 767,772 ****
--- 776,782 ----
// time at which the rootpane was last validated.
if (onBehalfAWTTime == null
|| lastValidatedAWTTime - onBehalfAWTTime.intValue() < 0) {
+ processing = true;
return new Dimension(width, height);
}
}
***************
*** 774,781 ****
}
// Implementation of Runnable.
public void run() {
! Dimension size = dequeue();
! if (size != null) {
// Set the frame's (and thus also the rootpane's) size.
if (verboseSizeLayout)
System.err.println("SWT->AWT thread: Setting size: " + size.width + " x " + size.height + " for " + swingComponent);
--- 784,795 ----
}
// Implementation of Runnable.
public void run() {
! assert EventQueue.isDispatchThread(); // On AWT event thread
! assert !processing;
! for (;;) {
! Dimension size = dequeue();
! if (size == null)
! break;
// Set the frame's (and thus also the rootpane's) size.
if (verboseSizeLayout)
System.err.println("SWT->AWT thread: Setting size: " + size.width + " x " + size.height + " for " + swingComponent);
***************
*** 783,789 ****
--- 797,813 ----
frame.setBounds(0, 0, Math.max(size.width, 0), Math.max(size.height, 0));
frame.validate();
}
+ // Test if another request was enqueued (from the SWT thread)
+ // while we were processing this one.
+ synchronized(this) {
+ processing = false;
+ if (!pending)
+ break;
+ }
+ // While this thread was resizing the frame, the SWT thread
+ // enqueued another request.
}
+ assert !processing;
}
}
private SetAWTSizeQueue setAWTSizeQueue = new SetAWTSizeQueue();