aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-05-27 16:30:12 +0800
committerPo Lu2023-05-27 16:30:12 +0800
commit327d2d013130ec745880b44573dcda3a6620faba (patch)
tree6e17ac215c8f772d64282953588dd95cd550aea5 /java
parentd33bf0a0afddb76598aa020f68402d0e19cfb65c (diff)
downloademacs-327d2d013130ec745880b44573dcda3a6620faba.tar.gz
emacs-327d2d013130ec745880b44573dcda3a6620faba.zip
Add extra thread-related checking
* java/org/gnu/emacs/EmacsService.java (EmacsService) (checkEmacsThread): New function. (fillPolygon, drawRectangle, drawLine, drawPoint, copyArea) (clearArea): * java/org/gnu/emacs/EmacsThread.java (EmacsThread): * java/org/gnu/emacs/EmacsView.java (EmacsView, swapBuffers): Call where appropriate.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsService.java30
-rw-r--r--java/org/gnu/emacs/EmacsThread.java2
-rw-r--r--java/org/gnu/emacs/EmacsView.java5
3 files changed, 36 insertions, 1 deletions
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index bb17d27bcf8..d2e52ed5e62 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -100,6 +100,10 @@ public final class EmacsService extends Service
100 information. */ 100 information. */
101 public static final boolean DEBUG_IC = false; 101 public static final boolean DEBUG_IC = false;
102 102
103 /* Flag that says whether or not to perform extra checks on threads
104 performing drawing calls. */
105 private static final boolean DEBUG_THREADS = false;
106
103 /* Return the directory leading to the directory in which native 107 /* Return the directory leading to the directory in which native
104 library files are stored on behalf of CONTEXT. */ 108 library files are stored on behalf of CONTEXT. */
105 109
@@ -309,10 +313,29 @@ public final class EmacsService extends Service
309 syncRunnable (runnable); 313 syncRunnable (runnable);
310 } 314 }
311 315
316
317
318 public static void
319 checkEmacsThread ()
320 {
321 if (DEBUG_THREADS)
322 {
323 if (Thread.currentThread () instanceof EmacsThread)
324 return;
325
326 throw new RuntimeException ("Emacs thread function"
327 + " called from other thread!");
328 }
329 }
330
331 /* These drawing functions must only be called from the Emacs
332 thread. */
333
312 public void 334 public void
313 fillRectangle (EmacsDrawable drawable, EmacsGC gc, 335 fillRectangle (EmacsDrawable drawable, EmacsGC gc,
314 int x, int y, int width, int height) 336 int x, int y, int width, int height)
315 { 337 {
338 checkEmacsThread ();
316 EmacsFillRectangle.perform (drawable, gc, x, y, 339 EmacsFillRectangle.perform (drawable, gc, x, y,
317 width, height); 340 width, height);
318 } 341 }
@@ -321,6 +344,7 @@ public final class EmacsService extends Service
321 fillPolygon (EmacsDrawable drawable, EmacsGC gc, 344 fillPolygon (EmacsDrawable drawable, EmacsGC gc,
322 Point points[]) 345 Point points[])
323 { 346 {
347 checkEmacsThread ();
324 EmacsFillPolygon.perform (drawable, gc, points); 348 EmacsFillPolygon.perform (drawable, gc, points);
325 } 349 }
326 350
@@ -328,6 +352,7 @@ public final class EmacsService extends Service
328 drawRectangle (EmacsDrawable drawable, EmacsGC gc, 352 drawRectangle (EmacsDrawable drawable, EmacsGC gc,
329 int x, int y, int width, int height) 353 int x, int y, int width, int height)
330 { 354 {
355 checkEmacsThread ();
331 EmacsDrawRectangle.perform (drawable, gc, x, y, 356 EmacsDrawRectangle.perform (drawable, gc, x, y,
332 width, height); 357 width, height);
333 } 358 }
@@ -336,6 +361,7 @@ public final class EmacsService extends Service
336 drawLine (EmacsDrawable drawable, EmacsGC gc, 361 drawLine (EmacsDrawable drawable, EmacsGC gc,
337 int x, int y, int x2, int y2) 362 int x, int y, int x2, int y2)
338 { 363 {
364 checkEmacsThread ();
339 EmacsDrawLine.perform (drawable, gc, x, y, 365 EmacsDrawLine.perform (drawable, gc, x, y,
340 x2, y2); 366 x2, y2);
341 } 367 }
@@ -344,6 +370,7 @@ public final class EmacsService extends Service
344 drawPoint (EmacsDrawable drawable, EmacsGC gc, 370 drawPoint (EmacsDrawable drawable, EmacsGC gc,
345 int x, int y) 371 int x, int y)
346 { 372 {
373 checkEmacsThread ();
347 EmacsDrawPoint.perform (drawable, gc, x, y); 374 EmacsDrawPoint.perform (drawable, gc, x, y);
348 } 375 }
349 376
@@ -353,6 +380,7 @@ public final class EmacsService extends Service
353 int srcX, int srcY, int width, int height, int destX, 380 int srcX, int srcY, int width, int height, int destX,
354 int destY) 381 int destY)
355 { 382 {
383 checkEmacsThread ();
356 EmacsCopyArea.perform (srcDrawable, gc, dstDrawable, 384 EmacsCopyArea.perform (srcDrawable, gc, dstDrawable,
357 srcX, srcY, width, height, destX, 385 srcX, srcY, width, height, destX,
358 destY); 386 destY);
@@ -361,6 +389,7 @@ public final class EmacsService extends Service
361 public void 389 public void
362 clearWindow (EmacsWindow window) 390 clearWindow (EmacsWindow window)
363 { 391 {
392 checkEmacsThread ();
364 window.clearWindow (); 393 window.clearWindow ();
365 } 394 }
366 395
@@ -368,6 +397,7 @@ public final class EmacsService extends Service
368 clearArea (EmacsWindow window, int x, int y, int width, 397 clearArea (EmacsWindow window, int x, int y, int width,
369 int height) 398 int height)
370 { 399 {
400 checkEmacsThread ();
371 window.clearArea (x, y, width, height); 401 window.clearArea (x, y, width, height);
372 } 402 }
373 403
diff --git a/java/org/gnu/emacs/EmacsThread.java b/java/org/gnu/emacs/EmacsThread.java
index 468c6530af0..1343b70bf5a 100644
--- a/java/org/gnu/emacs/EmacsThread.java
+++ b/java/org/gnu/emacs/EmacsThread.java
@@ -25,7 +25,7 @@ import java.util.Arrays;
25import android.os.Build; 25import android.os.Build;
26import android.util.Log; 26import android.util.Log;
27 27
28public class EmacsThread extends Thread 28public final class EmacsThread extends Thread
29{ 29{
30 private static final String TAG = "EmacsThread"; 30 private static final String TAG = "EmacsThread";
31 31
diff --git a/java/org/gnu/emacs/EmacsView.java b/java/org/gnu/emacs/EmacsView.java
index eb1d88ae242..09bc9d719d3 100644
--- a/java/org/gnu/emacs/EmacsView.java
+++ b/java/org/gnu/emacs/EmacsView.java
@@ -338,6 +338,7 @@ public final class EmacsView extends ViewGroup
338 public void 338 public void
339 damageRect (Rect damageRect) 339 damageRect (Rect damageRect)
340 { 340 {
341 EmacsService.checkEmacsThread ();
341 damageRegion.union (damageRect); 342 damageRegion.union (damageRect);
342 } 343 }
343 344
@@ -351,6 +352,10 @@ public final class EmacsView extends ViewGroup
351 Rect damageRect; 352 Rect damageRect;
352 Bitmap bitmap; 353 Bitmap bitmap;
353 354
355 /* Make sure this function is called only from the Emacs
356 thread. */
357 EmacsService.checkEmacsThread ();
358
354 damageRect = null; 359 damageRect = null;
355 360
356 /* Now see if there is a damage region. */ 361 /* Now see if there is a damage region. */