From 1c23b2b030c38d77fbfed94e0dfdc2d23c13a950 Mon Sep 17 00:00:00 2001 From: anashaty Date: Sat, 26 Aug 2017 14:53:36 +0100 Subject: [PATCH] 8080504: [macosx] SunToolkit.realSync() may hang Reviewed-by: serb, prr --- src/macosx/native/sun/awt/LWCToolkit.m | 2 +- src/macosx/native/sun/osxapp/NSApplicationAWT.h | 2 +- src/macosx/native/sun/osxapp/NSApplicationAWT.m | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/macosx/native/sun/awt/LWCToolkit.m b/src/macosx/native/sun/awt/LWCToolkit.m index f56f58770..08f0bb7a9 100644 --- a/src/macosx/native/sun/awt/LWCToolkit.m +++ b/src/macosx/native/sun/awt/LWCToolkit.m @@ -137,7 +137,7 @@ JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue if ([sharedApp isKindOfClass:[NSApplicationAWT class]]) { NSApplicationAWT* theApp = (NSApplicationAWT*)sharedApp; [theApp postDummyEvent]; - [theApp waitForDummyEvent]; + [theApp waitForDummyEvent:timeout]; } else { // could happen if we are embedded inside SWT application, // in this case just spin a single empty block through diff --git a/src/macosx/native/sun/osxapp/NSApplicationAWT.h b/src/macosx/native/sun/osxapp/NSApplicationAWT.h index 99c7d6317..1025cd7c5 100644 --- a/src/macosx/native/sun/osxapp/NSApplicationAWT.h +++ b/src/macosx/native/sun/osxapp/NSApplicationAWT.h @@ -38,7 +38,7 @@ - (void) setDockIconWithEnv:(JNIEnv *)env; - (void) postDummyEvent; - (void) postRunnableEvent:(void (^)())block; -- (void) waitForDummyEvent; +- (void) waitForDummyEvent:(long long) timeout; + (void) runAWTLoopWithApp:(NSApplication*)app; diff --git a/src/macosx/native/sun/osxapp/NSApplicationAWT.m b/src/macosx/native/sun/osxapp/NSApplicationAWT.m index 21576c0b2..aba26de17 100644 --- a/src/macosx/native/sun/osxapp/NSApplicationAWT.m +++ b/src/macosx/native/sun/osxapp/NSApplicationAWT.m @@ -397,8 +397,14 @@ AWT_ASSERT_APPKIT_THREAD; [pool drain]; } -- (void)waitForDummyEvent { - [seenDummyEventLock lockWhenCondition:YES]; +- (void)waitForDummyEvent:(long long) timeout { + if (timeout >= 0) { + double sec = ((double) timeout)/1000; + [seenDummyEventLock lockWhenCondition:YES + beforeDate:[NSDate dateWithTimeIntervalSinceNow:sec]]; + } else { + [seenDummyEventLock lockWhenCondition:YES]; + } [seenDummyEventLock unlock]; [seenDummyEventLock release]; -- GitLab