Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/native_NOTIOS/sun/osxapp/ThreadUtilities.h
38829 views
/*1* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifndef __THREADUTILITIES_H26#define __THREADUTILITIES_H2728#import <pthread.h>2930#import "AWT_debug.h"313233// --------------------------------------------------------------------------34#ifndef PRODUCT_BUILD3536// Turn on the AWT thread assert mechanism. See below for different variants.37// TODO: don't enable this for production builds...38#define AWT_THREAD_ASSERTS3940#endif /* PRODUCT_BUILD */41// --------------------------------------------------------------------------4243// --------------------------------------------------------------------------44#ifdef AWT_THREAD_ASSERTS4546// Turn on to have awt thread asserts display a message on the console.47#define AWT_THREAD_ASSERTS_MESSAGES4849// Turn on to have awt thread asserts use an environment variable switch to50// determine if assert should really be called.51//#define AWT_THREAD_ASSERTS_ENV_ASSERT5253// Define AWT_THREAD_ASSERTS_WAIT to make asserts halt the asserting thread54// for debugging purposes.55//#define AWT_THREAD_ASSERTS_WAIT5657#ifdef AWT_THREAD_ASSERTS_MESSAGES5859#define AWT_THREAD_ASSERTS_NOT_APPKIT_MESSAGE \60AWT_DEBUG_LOG(@"Not running on AppKit thread 0 when expected.")6162#define AWT_THREAD_ASSERTS_ON_APPKIT_MESSAGE \63AWT_DEBUG_LOG(@"Running on AppKit thread 0 when not expected.")6465#ifdef AWT_THREAD_ASSERTS_ENV_ASSERT6667extern int sAWTThreadAsserts;68#define AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK \69do { \70if (sAWTThreadAsserts) { \71NSLog(@"\tPlease run this java program again with setenv COCOA_AWT_DISABLE_THREAD_ASSERTS to proceed with a warning."); \72assert(NO); \73} \74} while (0)7576#else7778#define AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK do {} while (0)7980#endif /* AWT_THREAD_ASSERTS_ENV_ASSERT */8182#define AWT_ASSERT_APPKIT_THREAD \83do { \84if (pthread_main_np() == 0) { \85AWT_THREAD_ASSERTS_NOT_APPKIT_MESSAGE; \86AWT_DEBUG_BUG_REPORT_MESSAGE; \87AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK; \88} \89} while (0)9091#define AWT_ASSERT_NOT_APPKIT_THREAD \92do { \93if (pthread_main_np() != 0) { \94AWT_THREAD_ASSERTS_ON_APPKIT_MESSAGE; \95AWT_DEBUG_BUG_REPORT_MESSAGE; \96AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK; \97} \98} while (0)99100#endif /* AWT_THREAD_ASSERTS_MESSAGES */101102#ifdef AWT_THREAD_ASSERTS_WAIT103104#define AWT_ASSERT_APPKIT_THREAD \105do { \106while (pthread_main_np() == 0) {} \107} while (0)108109#define AWT_ASSERT_NOT_APPKIT_THREAD \110do { \111while (pthread_main_np() != 0) {} \112} while (0)113114#endif /* AWT_THREAD_ASSERTS_WAIT */115116#else /* AWT_THREAD_ASSERTS */117118#define AWT_ASSERT_APPKIT_THREAD do {} while (0)119#define AWT_ASSERT_NOT_APPKIT_THREAD do {} while (0)120121#endif /* AWT_THREAD_ASSERTS */122// --------------------------------------------------------------------------123124__attribute__((visibility("default")))125@interface ThreadUtilities { }126127+ (JNIEnv*)getJNIEnv;128+ (JNIEnv*)getJNIEnvUncached;129+ (void)detachCurrentThread;130+ (void)setAppkitThreadGroup:(jobject)group;131+ (void)setAWTEmbedded:(BOOL)embedded;132+ (BOOL)isAWTEmbedded;133134//Wrappers for the corresponding JNFRunLoop methods with a check for main thread135+ (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block;136+ (void)performOnMainThread:(SEL)aSelector on:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait;137@end138139void OSXAPP_SetJavaVM(JavaVM *vm);140141#endif /* __THREADUTILITIES_H */142143144