diff options
| author | fnasser <fnasser@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-01-19 17:38:36 +0000 |
|---|---|---|
| committer | fnasser <fnasser@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-01-19 17:38:36 +0000 |
| commit | 3a61636ca75934eeae45792559c5117c8f95d505 (patch) | |
| tree | bdcd342767edb16816790bda374b2cd9aab08828 /libjava/java | |
| parent | 3fb411b25cfd867eb7f139e6920840810a09058b (diff) | |
| download | ppe42-gcc-3a61636ca75934eeae45792559c5117c8f95d505.tar.gz ppe42-gcc-3a61636ca75934eeae45792559c5117c8f95d505.zip | |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@76161 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java')
| -rw-r--r-- | libjava/java/awt/EventQueue.java | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/libjava/java/awt/EventQueue.java b/libjava/java/awt/EventQueue.java index 4cb0703ec62..7df40edee38 100644 --- a/libjava/java/awt/EventQueue.java +++ b/libjava/java/awt/EventQueue.java @@ -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; + } } } |

