author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 25564 | jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m@871d3490f14d |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
15985
diff
changeset
|
2 |
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#import <AppKit/AppKit.h> |
|
27 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
|
28 |
#import <objc/message.h> |
|
29 |
||
30 |
#import "ThreadUtilities.h" |
|
31 |
||
32 |
||
33 |
// The following must be named "jvm", as there are extern references to it in AWT |
|
34 |
JavaVM *jvm = NULL; |
|
35 |
static JNIEnv *appKitEnv = NULL; |
|
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
36 |
static jobject appkitThreadGroup = NULL; |
23893 | 37 |
|
25099
ba8a24b2576f
8043646: libosxapp.dylib fails to build on Mac OS 10.9 with clang
pchelko
parents:
23921
diff
changeset
|
38 |
static inline void attachCurrentThread(void** env) { |
23893 | 39 |
if ([NSThread isMainThread]) { |
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
40 |
JavaVMAttachArgs args; |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
41 |
args.version = JNI_VERSION_1_4; |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
42 |
args.name = "AppKit Thread"; |
23893 | 43 |
args.group = appkitThreadGroup; |
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
44 |
(*jvm)->AttachCurrentThreadAsDaemon(jvm, env, &args); |
23893 | 45 |
} else { |
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
46 |
(*jvm)->AttachCurrentThreadAsDaemon(jvm, env, NULL); |
23893 | 47 |
} |
48 |
} |
|
12047 | 49 |
|
50 |
@implementation ThreadUtilities |
|
51 |
||
52 |
+ (JNIEnv*)getJNIEnv { |
|
53 |
AWT_ASSERT_APPKIT_THREAD; |
|
54 |
if (appKitEnv == NULL) { |
|
23893 | 55 |
attachCurrentThread((void **)&appKitEnv); |
12047 | 56 |
} |
57 |
return appKitEnv; |
|
58 |
} |
|
59 |
||
60 |
+ (JNIEnv*)getJNIEnvUncached { |
|
61 |
JNIEnv *env = NULL; |
|
23893 | 62 |
attachCurrentThread((void **)&env); |
12047 | 63 |
return env; |
64 |
} |
|
65 |
||
23893 | 66 |
+ (void)detachCurrentThread { |
67 |
(*jvm)->DetachCurrentThread(jvm); |
|
68 |
} |
|
69 |
||
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
70 |
+ (void)setAppkitThreadGroup:(jobject)group { |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
71 |
appkitThreadGroup = group; |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
72 |
} |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23893
diff
changeset
|
73 |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14342
diff
changeset
|
74 |
+ (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block { |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14342
diff
changeset
|
75 |
if ([NSThread isMainThread] && wait == YES) { |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14342
diff
changeset
|
76 |
block(); |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14342
diff
changeset
|
77 |
} else { |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14342
diff
changeset
|
78 |
[JNFRunLoop performOnMainThreadWaiting:wait withBlock:block]; |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14342
diff
changeset
|
79 |
} |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14342
diff
changeset
|
80 |
} |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14342
diff
changeset
|
81 |
|
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
82 |
+ (void)performOnMainThread:(SEL)aSelector on:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait { |
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
83 |
if ([NSThread isMainThread] && wait == YES) { |
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
84 |
[target performSelector:aSelector withObject:arg]; |
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
85 |
} else { |
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
86 |
[JNFRunLoop performOnMainThread:aSelector on:target withObject:arg waitUntilDone:wait]; |
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
87 |
} |
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
88 |
} |
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14753
diff
changeset
|
89 |
|
12047 | 90 |
@end |
91 |
||
92 |
||
93 |
void OSXAPP_SetJavaVM(JavaVM *vm) |
|
94 |
{ |
|
95 |
jvm = vm; |
|
96 |
} |
|
97 |