changeset 4975:ddb615988fbf

7148289: [macosx] Deadlock in sun.lwawt.macosx.CWrapper$NSScreen.visibleFrame Reviewed-by: anthony
author kizune
date Thu, 03 May 2012 22:18:06 +0400
parents 1e3829d2447c
children b4a447259412
files src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java src/macosx/native/sun/awt/LWCToolkit.m
diffstat 3 files changed, 42 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java	Mon Apr 30 21:02:31 2012 -0700
+++ b/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java	Thu May 03 22:18:06 2012 +0400
@@ -27,9 +27,9 @@
 
 import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
 
-// TODO:BG this class is really a NOOP right now, but should be filled in if needed.
+final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler {
+    private final LWCToolkit toolkit = (LWCToolkit)java.awt.Toolkit.getDefaultToolkit();
 
-final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler {
     public void lock() {
     }
 
@@ -41,9 +41,10 @@
     }
 
     public void enter() {
+        toolkit.startNativeNestedEventLoop();
     }
 
     public void exit() {
+        toolkit.stopNativeNestedEventLoop();
     }
-
 }
--- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Mon Apr 30 21:02:31 2012 -0700
+++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Thu May 03 22:18:06 2012 +0400
@@ -63,6 +63,10 @@
 
     private static native void initIDs();
 
+    static native void startNativeNestedEventLoop();
+
+    static native void stopNativeNestedEventLoop();
+
     private static CInputMethodDescriptor sInputMethodDescriptor;
 
     static {
--- a/src/macosx/native/sun/awt/LWCToolkit.m	Mon Apr 30 21:02:31 2012 -0700
+++ b/src/macosx/native/sun/awt/LWCToolkit.m	Thu May 03 22:18:06 2012 +0400
@@ -42,6 +42,7 @@
 @implementation AWTToolkit
 
 static long eventCount;
+static bool shouldKeepRunningNestedLoop = NO;
 
 + (long) getEventCount{
     return eventCount;
@@ -456,3 +457,36 @@
 {
 
 }
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    startNativeNestedEventLoop
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_startNativeNestedEventLoop
+(JNIEnv *env, jclass cls)
+{
+    if(!shouldKeepRunningNestedLoop) {
+        NSRunLoop *theRL = [NSRunLoop currentRunLoop];
+        NSApplication * app = [NSApplication sharedApplication];
+        shouldKeepRunningNestedLoop = YES;
+        while (shouldKeepRunningNestedLoop && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
+        {
+            NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
+            if (event != nil) {
+                [app sendEvent: event];
+            }
+        }
+    }
+}
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    stopNativeNestedEventLoop
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeNestedEventLoop
+(JNIEnv *env, jclass cls)
+{
+    shouldKeepRunningNestedLoop = NO;
+}