[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/android 327d2d01313 1/7: Add extra thread-related checking
From: |
Po Lu |
Subject: |
feature/android 327d2d01313 1/7: Add extra thread-related checking |
Date: |
Mon, 29 May 2023 06:07:12 -0400 (EDT) |
branch: feature/android
commit 327d2d013130ec745880b44573dcda3a6620faba
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
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.
---
java/org/gnu/emacs/EmacsService.java | 30 ++++++++++++++++++++++++++++++
java/org/gnu/emacs/EmacsThread.java | 2 +-
java/org/gnu/emacs/EmacsView.java | 5 +++++
3 files changed, 36 insertions(+), 1 deletion(-)
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
information. */
public static final boolean DEBUG_IC = false;
+ /* Flag that says whether or not to perform extra checks on threads
+ performing drawing calls. */
+ private static final boolean DEBUG_THREADS = false;
+
/* Return the directory leading to the directory in which native
library files are stored on behalf of CONTEXT. */
@@ -309,10 +313,29 @@ public final class EmacsService extends Service
syncRunnable (runnable);
}
+
+
+ public static void
+ checkEmacsThread ()
+ {
+ if (DEBUG_THREADS)
+ {
+ if (Thread.currentThread () instanceof EmacsThread)
+ return;
+
+ throw new RuntimeException ("Emacs thread function"
+ + " called from other thread!");
+ }
+ }
+
+ /* These drawing functions must only be called from the Emacs
+ thread. */
+
public void
fillRectangle (EmacsDrawable drawable, EmacsGC gc,
int x, int y, int width, int height)
{
+ checkEmacsThread ();
EmacsFillRectangle.perform (drawable, gc, x, y,
width, height);
}
@@ -321,6 +344,7 @@ public final class EmacsService extends Service
fillPolygon (EmacsDrawable drawable, EmacsGC gc,
Point points[])
{
+ checkEmacsThread ();
EmacsFillPolygon.perform (drawable, gc, points);
}
@@ -328,6 +352,7 @@ public final class EmacsService extends Service
drawRectangle (EmacsDrawable drawable, EmacsGC gc,
int x, int y, int width, int height)
{
+ checkEmacsThread ();
EmacsDrawRectangle.perform (drawable, gc, x, y,
width, height);
}
@@ -336,6 +361,7 @@ public final class EmacsService extends Service
drawLine (EmacsDrawable drawable, EmacsGC gc,
int x, int y, int x2, int y2)
{
+ checkEmacsThread ();
EmacsDrawLine.perform (drawable, gc, x, y,
x2, y2);
}
@@ -344,6 +370,7 @@ public final class EmacsService extends Service
drawPoint (EmacsDrawable drawable, EmacsGC gc,
int x, int y)
{
+ checkEmacsThread ();
EmacsDrawPoint.perform (drawable, gc, x, y);
}
@@ -353,6 +380,7 @@ public final class EmacsService extends Service
int srcX, int srcY, int width, int height, int destX,
int destY)
{
+ checkEmacsThread ();
EmacsCopyArea.perform (srcDrawable, gc, dstDrawable,
srcX, srcY, width, height, destX,
destY);
@@ -361,6 +389,7 @@ public final class EmacsService extends Service
public void
clearWindow (EmacsWindow window)
{
+ checkEmacsThread ();
window.clearWindow ();
}
@@ -368,6 +397,7 @@ public final class EmacsService extends Service
clearArea (EmacsWindow window, int x, int y, int width,
int height)
{
+ checkEmacsThread ();
window.clearArea (x, y, width, height);
}
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;
import android.os.Build;
import android.util.Log;
-public class EmacsThread extends Thread
+public final class EmacsThread extends Thread
{
private static final String TAG = "EmacsThread";
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
public void
damageRect (Rect damageRect)
{
+ EmacsService.checkEmacsThread ();
damageRegion.union (damageRect);
}
@@ -351,6 +352,10 @@ public final class EmacsView extends ViewGroup
Rect damageRect;
Bitmap bitmap;
+ /* Make sure this function is called only from the Emacs
+ thread. */
+ EmacsService.checkEmacsThread ();
+
damageRect = null;
/* Now see if there is a damage region. */
- feature/android updated (d33bf0a0afd -> 1a1cf6b86fc), Po Lu, 2023/05/29
- feature/android 327d2d01313 1/7: Add extra thread-related checking,
Po Lu <=
- feature/android 00671b18438 2/7: Implement android_copy_area in C, Po Lu, 2023/05/29
- feature/android 787c947028c 5/7: ; * src/android.c (android_blit_copy): Fix typos., Po Lu, 2023/05/29
- feature/android 9a353545933 3/7: Update Android port, Po Lu, 2023/05/29
- feature/android 7fdde02f321 4/7: Work around more problems with Bitmaps, Po Lu, 2023/05/29
- feature/android 1a1cf6b86fc 7/7: Merge remote-tracking branch 'origin/master' into feature/android, Po Lu, 2023/05/29
- feature/android 1088a8e8dab 6/7: Update Android port, Po Lu, 2023/05/29