changeset 5030:665d7e1e7252

7171163: [macosx] Shortcomings in the design of the secondary native event loop made JavaFX DnD deadlock Reviewed-by: art, anthony
author kizune
date Fri, 25 May 2012 16:06:22 +0400
parents 7647f9201e31
children 39db51e1aa62
files src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java src/macosx/native/sun/awt/LWCToolkit.m src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java
diffstat 4 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java	Thu May 24 17:17:58 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java	Fri May 25 16:06:22 2012 +0400
@@ -41,10 +41,12 @@
     }
 
     public void enter() {
+        // Despite the naming of this method, on MacOS only one
+        // event is read and dispatched before this method returns.
+        // This call is non-blocking and does not wait for an event
         toolkit.startNativeNestedEventLoop();
     }
 
     public void exit() {
-        toolkit.stopNativeNestedEventLoop();
     }
 }
--- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Thu May 24 17:17:58 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Fri May 25 16:06:22 2012 +0400
@@ -63,8 +63,15 @@
 
     private static native void initIDs();
 
+    // On Mac OS we don't need to actually start the new event loop since there is
+    // a mechanic that allows us to just reschedule the next event in a native event loop
+    // for immediate execution and because this method is being called repeatedly we just
+    // executing one such event every time we call this method
     static native void startNativeNestedEventLoop();
 
+    // Since we don't start an additional event loop this method is a no-op
+    // and shouldn't be called, left only for the better understanding of the concept on
+    // other OS'es
     static native void stopNativeNestedEventLoop();
 
     private static CInputMethodDescriptor sInputMethodDescriptor;
--- a/src/macosx/native/sun/awt/LWCToolkit.m	Thu May 24 17:17:58 2012 +0400
+++ b/src/macosx/native/sun/awt/LWCToolkit.m	Fri May 25 16:06:22 2012 +0400
@@ -42,7 +42,6 @@
 @implementation AWTToolkit
 
 static long eventCount;
-static bool shouldKeepRunningNestedLoop = NO;
 
 + (long) getEventCount{
     return eventCount;
@@ -466,17 +465,13 @@
 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];
-            }
-        }
+    // Simply get the next event in native loop and pass it to execution
+    // We'll be called repeatedly so there's no need to block here
+    NSRunLoop *theRL = [NSRunLoop currentRunLoop];
+    NSApplication * app = [NSApplication sharedApplication];
+    NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
+    if (event != nil) {
+        [app sendEvent: event];
     }
 }
 
@@ -488,5 +483,5 @@
 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeNestedEventLoop
 (JNIEnv *env, jclass cls)
 {
-    shouldKeepRunningNestedLoop = NO;
+//    At this moment it seems that this method should be no-op
 }
--- a/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java	Thu May 24 17:17:58 2012 +0400
+++ b/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java	Fri May 25 16:06:22 2012 +0400
@@ -498,7 +498,7 @@
         postDropTargetEvent(component, x, y, dropAction, actions,
                             formats, nativeCtxt,
                             SunDropTargetEvent.MOUSE_DROPPED,
-                            !SunDropTargetContextPeer.DISPATCH_SYNC);
+                            SunDropTargetContextPeer.DISPATCH_SYNC);
     }
 
     /**