Mercurial > projects > dwt-linux
diff dwt/graphics/Device.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | 06a1f6829310 |
children | 5a30aa9820f3 |
line wrap: on
line diff
--- a/dwt/graphics/Device.d Mon May 12 15:36:37 2008 +0200 +++ b/dwt/graphics/Device.d Mon May 12 19:13:01 2008 +0200 @@ -57,6 +57,7 @@ bool tracking; Exception [] errors; Object [] objects; + Object trackingLock; /* Colormap and reference count */ GdkColor *[] gdkColors; @@ -99,8 +100,6 @@ static bool CAIRO_LOADED; -// static Object CREATE_LOCK; - /* * TEMPORARY CODE. When a graphics object is * created and the device parameter is null, @@ -157,7 +156,6 @@ * @see #init * @see DeviceData */ - public this(DeviceData data) { handler_ids = new int [log_domains.length]; debugging = DEBUG; @@ -171,13 +169,11 @@ if (tracking) { errors = new Exception [128]; objects = new Object [128]; + trackingLock = new Object (); } create (data); init_ (); register (this); - - /* Initialize the system font slot */ - systemFont = getSystemFont (); } } @@ -236,25 +232,32 @@ * @see #checkDevice */ public void dispose () { - if (isDisposed()) return; - checkDevice (); - release (); - destroy (); - deregister (this); - xDisplay = null; - disposed = true; - if (tracking) { - objects = null; - errors = null; + synchronized (Device.classinfo) { + if (isDisposed()) return; + checkDevice (); + release (); + destroy (); + deregister (this); + xDisplay = null; + disposed = true; + if (tracking) { + synchronized (trackingLock) { + objects = null; + errors = null; + trackingLock = null; + } + } } } void dispose_Object (Object object) { - for (int i=0; i<objects.length; i++) { - if (objects [i] is object) { - objects [i] = null; - errors [i] = null; - return; + synchronized (trackingLock) { + for (int i=0; i<objects.length; i++) { + if (objects [i] is object) { + objects [i] = null; + errors [i] = null; + return; + } } } } @@ -324,20 +327,26 @@ DeviceData data = new DeviceData (); data.debugging = debugging; data.tracking = tracking; - int count = 0, length = 0; - if (tracking) length = objects.length; - for (int i=0; i<length; i++) { - if (objects [i] !is null) count++; - } - int index = 0; - data.objects = new Object [count]; - data.errors = new Exception [count]; - for (int i=0; i<length; i++) { - if (objects [i] !is null) { - data.objects [index] = objects [i]; - data.errors [index] = errors [i]; - index++; + if (tracking) { + synchronized (trackingLock) { + int count = 0, length = objects.length; + for (int i=0; i<length; i++) { + if (objects [i] !is null) count++; + } + int index = 0; + data.objects = new Object [count]; + data.errors = new Exception [count]; + for (int i=0; i<length; i++) { + if (objects [i] !is null) { + data.objects [index] = objects [i]; + data.errors [index] = errors [i]; + index++; + } + } } + } else { + data.objects = null; + data.errors = null; } return data; } @@ -611,6 +620,9 @@ shellHandle = OS.gtk_window_new(OS.GTK_WINDOW_TOPLEVEL); if (shellHandle is null) DWT.error(DWT.ERROR_NO_HANDLES); OS.gtk_widget_realize(shellHandle); + + /* Initialize the system font slot */ + systemFont = getSystemFont (); } /** @@ -654,7 +666,9 @@ * @return <code>true</code> when the device is disposed and <code>false</code> otherwise */ public bool isDisposed () { - return disposed; + synchronized (Device.classinfo) { + return disposed; + } } /** @@ -693,21 +707,23 @@ } void new_Object (Object object) { - for (int i=0; i<objects.length; i++) { - if (objects [i] is null) { - objects [i] = object; - errors [i] = new Exception (""); - return; + synchronized (trackingLock) { + for (int i=0; i<objects.length; i++) { + if (objects [i] is null) { + objects [i] = object; + errors [i] = new Exception (""); + return; + } } + Object [] newObjects = new Object [objects.length + 128]; + System.arraycopy (objects, 0, newObjects, 0, objects.length); + newObjects [objects.length] = object; + objects = newObjects; + Exception [] newErrors = new Exception [errors.length + 128]; + System.arraycopy (errors, 0, newErrors, 0, errors.length); + newErrors [errors.length] = new Exception (""); + errors = newErrors; } - Object [] newObjects = new Object [objects.length + 128]; - System.arraycopy (objects, 0, newObjects, 0, objects.length); - newObjects [objects.length] = object; - objects = newObjects; - Exception [] newErrors = new Exception [errors.length + 128]; - System.arraycopy (errors, 0, newErrors, 0, errors.length); - newErrors [errors.length] = new Exception (""); - errors = newErrors; } static synchronized void register (Device device) {