summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-12-06 22:21:16 +0000
committerRoman Kennke <roman@kennke.org>2006-12-06 22:21:16 +0000
commit42c78aed7bf2ead1b45095a5a6030e7b5e7a19f7 (patch)
tree86715f0e8c63f1a68d121135f369163c3771b92c
parentbfe33aa5c92f11d84706cdeef14c7aea7a1533b0 (diff)
downloadclasspath-42c78aed7bf2ead1b45095a5a6030e7b5e7a19f7.tar.gz
2006-12-06 Roman Kennke <kennke@aicas.com>
* gnu/java/awt/peer/gtk/AsyncImage.java (Loader.run): Synchronize on the AsyncImage to avoid threading issues. (addObservers): Check for obs==null outside and synchronize on this inside to avoid locking issues. (checkImage): New helper method. (notifyObservers): Check that the correct lock is held and remove actual locking. * gnu/java/awt/peer/gtk/GtkToolkit.java (checkImage): Added special handling for AsyncImages.
-rw-r--r--ChangeLog13
-rw-r--r--gnu/java/awt/peer/gtk/AsyncImage.java67
-rw-r--r--gnu/java/awt/peer/gtk/GtkToolkit.java3
3 files changed, 56 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 992a00c83..4ce16cda9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2006-12-06 Roman Kennke <kennke@aicas.com>
+ * gnu/java/awt/peer/gtk/AsyncImage.java
+ (Loader.run): Synchronize on the AsyncImage to avoid threading
+ issues.
+ (addObservers): Check for obs==null outside and synchronize on
+ this inside to avoid locking issues.
+ (checkImage): New helper method.
+ (notifyObservers): Check that the correct lock is held and
+ remove actual locking.
+ * gnu/java/awt/peer/gtk/GtkToolkit.java
+ (checkImage): Added special handling for AsyncImages.
+
+2006-12-06 Roman Kennke <kennke@aicas.com>
+
* examples/gnu/classpath/examples/swing/Demo.java
(getIcon): Made package private.
* examples/gnu/classpath/examples/swing/HtmlDemo.java
diff --git a/gnu/java/awt/peer/gtk/AsyncImage.java b/gnu/java/awt/peer/gtk/AsyncImage.java
index e55b4aafe..5238bfe74 100644
--- a/gnu/java/awt/peer/gtk/AsyncImage.java
+++ b/gnu/java/awt/peer/gtk/AsyncImage.java
@@ -126,9 +126,12 @@ public class AsyncImage
image = null;
}
realImage = GtkToolkit.imageOrError(image);
- notifyObservers(ImageObserver.ALLBITS | ImageObserver.HEIGHT
- | ImageObserver.WIDTH | ImageObserver.PROPERTIES);
- observers = null; // Not needed anymore.
+ synchronized (AsyncImage.this)
+ {
+ notifyObservers(ImageObserver.ALLBITS | ImageObserver.HEIGHT
+ | ImageObserver.WIDTH | ImageObserver.PROPERTIES);
+ observers = null; // Not needed anymore.
+ }
}
}
@@ -212,28 +215,30 @@ public class AsyncImage
void addObserver(ImageObserver obs)
{
- // This field gets null when image loading is complete and we don't
- // need to store any more observers.
- HashSet observs = observers;
- if (observs != null)
+ if (obs != null)
{
- if (obs != null)
+ synchronized (this)
{
- synchronized (observs)
+ // This field gets null when image loading is complete and we don't
+ // need to store any more observers.
+ HashSet observs = observers;
+ if (observs != null)
{
observs.add(obs);
}
+ else
+ {
+ // When the image is complete, notify the observer. Dunno if
+ // that's really needed, but to be sure.
+ obs.imageUpdate(this, ImageObserver.WIDTH
+ | ImageObserver.HEIGHT
+ |ImageObserver.ALLBITS
+ | ImageObserver.PROPERTIES, 0, 0,
+ realImage.getWidth(null),
+ realImage.getHeight(null));
+ }
}
}
- else if (obs != null)
- {
- // When the image is complete, notify the observer. Dunno if that's
- // really needed, but to be sure.
- obs.imageUpdate(this, ImageObserver.WIDTH | ImageObserver.HEIGHT
- |ImageObserver.ALLBITS | ImageObserver.PROPERTIES,
- 0, 0, realImage.getWidth(null),
- realImage.getHeight(null));
- }
}
static Image realImage(Image img, ImageObserver obs)
@@ -250,21 +255,29 @@ public class AsyncImage
void notifyObservers(int status)
{
+ assert Thread.holdsLock(this);
// This field gets null when image loading is complete.
HashSet observs = observers;
if (observs != null)
{
- synchronized (observs)
+ Image r = realImage;
+ Iterator i = observs.iterator();
+ while (i.hasNext())
{
- Image r = realImage;
- Iterator i = observs.iterator();
- while (i.hasNext())
- {
- ImageObserver obs = (ImageObserver) i.next();
- obs.imageUpdate(this, status, 0, 0, r.getWidth(null),
- r.getHeight(null));
- }
+ ImageObserver obs = (ImageObserver) i.next();
+ obs.imageUpdate(this, status, 0, 0, r.getWidth(null),
+ r.getHeight(null));
}
}
}
+
+ int checkImage(ImageObserver obs)
+ {
+ addObserver(obs);
+ int flags = 0;
+ if (realImage != null)
+ flags = ImageObserver.ALLBITS | ImageObserver.WIDTH
+ | ImageObserver.HEIGHT | ImageObserver.PROPERTIES;
+ return flags;
+ }
}
diff --git a/gnu/java/awt/peer/gtk/GtkToolkit.java b/gnu/java/awt/peer/gtk/GtkToolkit.java
index 9b654f10e..f746a4747 100644
--- a/gnu/java/awt/peer/gtk/GtkToolkit.java
+++ b/gnu/java/awt/peer/gtk/GtkToolkit.java
@@ -176,6 +176,9 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit
if (image instanceof GtkImage)
return ((GtkImage) image).checkImage (observer);
+ if (image instanceof AsyncImage)
+ return ((AsyncImage) image).checkImage(observer);
+
if (observer != null)
observer.imageUpdate (image, status,
-1, -1,