EventQueue.java (pop): Prevent racing condition to add events to the queue out of order by acquiring...
* java/awt/EventQueue.java (pop): Prevent racing condition to add events to the queue out of order by acquiring locks in the proper order and not by releasing one before acquiring the other. From-SVN: r76161
This commit is contained in:
parent
8f9f8d71c7
commit
605d10f7f2
2 changed files with 26 additions and 18 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-01-19 Fernando Nasser <fnasser@redhat.com>
|
||||
|
||||
* java/awt/EventQueue.java (pop): Prevent racing condition to add
|
||||
events to the queue out of order by acquiring locks in the proper
|
||||
order and not by releasing one before acquiring the other.
|
||||
|
||||
2004-01-19 Fernando Nasser <fnasser@redhat.com>
|
||||
|
||||
* gnu/java/awt/peer/gtk/TestAWT.java (DialogWindow): Make text not
|
||||
|
|
|
@ -358,32 +358,34 @@ public class EventQueue
|
|||
if (prev == null)
|
||||
throw new EmptyStackException();
|
||||
|
||||
// Don't synchronize both this and prev at the same time, or deadlock could
|
||||
// occur.
|
||||
/* The order is important here, we must get the prev lock first,
|
||||
or deadlock could occur as callers usually get here following
|
||||
prev's next pointer, and thus obtain prev's lock before trying
|
||||
to get this lock. */
|
||||
synchronized (prev)
|
||||
{
|
||||
prev.next = next;
|
||||
if (next != null)
|
||||
next.prev = prev;
|
||||
}
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
int i = next_out;
|
||||
while (i != next_in)
|
||||
synchronized (this)
|
||||
{
|
||||
prev.postEvent(queue[i]);
|
||||
next_out = i;
|
||||
if (++i == queue.length)
|
||||
i = 0;
|
||||
}
|
||||
// Empty the queue so it can be reused
|
||||
next_in = 0;
|
||||
next_out = 0;
|
||||
int i = next_out;
|
||||
while (i != next_in)
|
||||
{
|
||||
prev.postEvent(queue[i]);
|
||||
next_out = i;
|
||||
if (++i == queue.length)
|
||||
i = 0;
|
||||
}
|
||||
// Empty the queue so it can be reused
|
||||
next_in = 0;
|
||||
next_out = 0;
|
||||
|
||||
// Tell our EventDispatchThread that it can end execution
|
||||
dispatchThread.interrupt ();
|
||||
dispatchThread = null;
|
||||
// Tell our EventDispatchThread that it can end execution
|
||||
dispatchThread.interrupt ();
|
||||
dispatchThread = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue