提交 8db67d62 编写于 作者: S serb

7124271: [macosx] RealSync test failure

Reviewed-by: alexsch, azvegint
上级 1c23b2b0
...@@ -131,13 +131,23 @@ static long eventCount; ...@@ -131,13 +131,23 @@ static long eventCount;
JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_LWCToolkit_nativeSyncQueue
(JNIEnv *env, jobject self, jlong timeout) (JNIEnv *env, jobject self, jlong timeout)
{ {
int currentEventNum = [AWTToolkit getEventCount]; long currentEventNum = [AWTToolkit getEventCount];
NSApplication* sharedApp = [NSApplication sharedApplication]; NSApplication* sharedApp = [NSApplication sharedApplication];
if ([sharedApp isKindOfClass:[NSApplicationAWT class]]) { if ([sharedApp isKindOfClass:[NSApplicationAWT class]]) {
NSApplicationAWT* theApp = (NSApplicationAWT*)sharedApp; NSApplicationAWT* theApp = (NSApplicationAWT*)sharedApp;
[theApp postDummyEvent]; // We use two different API to post events to the application,
[theApp waitForDummyEvent:timeout]; // - [NSApplication postEvent]
// - CGEventPost(), see CRobot.m
// It was found that if we post an event via CGEventPost in robot and
// immediately after this we will post the second event via
// [NSApp postEvent] then sometimes the second event will be handled
// first. The opposite isn't proved, but we use both here to be safer.
[theApp postDummyEvent:false];
[theApp waitForDummyEvent:timeout / 2.0];
[theApp postDummyEvent:true];
[theApp waitForDummyEvent:timeout / 2.0];
} else { } else {
// could happen if we are embedded inside SWT application, // could happen if we are embedded inside SWT application,
// in this case just spin a single empty block through // in this case just spin a single empty block through
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
- (void) finishLaunching; - (void) finishLaunching;
- (void) registerWithProcessManager; - (void) registerWithProcessManager;
- (void) setDockIconWithEnv:(JNIEnv *)env; - (void) setDockIconWithEnv:(JNIEnv *)env;
- (void) postDummyEvent; - (void) postDummyEvent:(bool) useCocoa;
- (void) postRunnableEvent:(void (^)())block; - (void) postRunnableEvent:(void (^)())block;
- (void) waitForDummyEvent:(long long) timeout; - (void) waitForDummyEvent:(double) timeout;
+ (void) runAWTLoopWithApp:(NSApplication*)app; + (void) runAWTLoopWithApp:(NSApplication*)app;
......
...@@ -377,9 +377,7 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -377,9 +377,7 @@ AWT_ASSERT_APPKIT_THREAD;
[pool drain]; [pool drain];
} }
- (void)postDummyEvent:(bool)useCocoa {
- (void)postDummyEvent {
seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO]; seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime; dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;
...@@ -393,19 +391,28 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -393,19 +391,28 @@ AWT_ASSERT_APPKIT_THREAD;
subtype: 0 subtype: 0
data1: 0 data1: 0
data2: 0]; data2: 0];
[NSApp postEvent: event atStart: NO]; if (useCocoa) {
[NSApp postEvent:event atStart:NO];
} else {
ProcessSerialNumber psn;
GetCurrentProcess(&psn);
CGEventPostToPSN(&psn, [event CGEvent]);
}
[pool drain]; [pool drain];
} }
- (void)waitForDummyEvent:(long long) timeout { - (void)waitForDummyEvent:(double)timeout {
bool unlock = true;
if (timeout >= 0) { if (timeout >= 0) {
double sec = ((double) timeout)/1000; double sec = timeout / 1000;
[seenDummyEventLock lockWhenCondition:YES unlock = [seenDummyEventLock lockWhenCondition:YES
beforeDate:[NSDate dateWithTimeIntervalSinceNow:sec]]; beforeDate:[NSDate dateWithTimeIntervalSinceNow:sec]];
} else { } else {
[seenDummyEventLock lockWhenCondition:YES]; [seenDummyEventLock lockWhenCondition:YES];
} }
if (unlock) {
[seenDummyEventLock unlock]; [seenDummyEventLock unlock];
}
[seenDummyEventLock release]; [seenDummyEventLock release];
seenDummyEventLock = nil; seenDummyEventLock = nil;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册