81 #endif /* AWT_THREAD_ASSERTS_ENV_ASSERT */ 82 83 #define AWT_ASSERT_APPKIT_THREAD \ 84 do { \ 85 if (pthread_main_np() == 0) { \ 86 AWT_THREAD_ASSERTS_NOT_APPKIT_MESSAGE; \ 87 AWT_DEBUG_BUG_REPORT_MESSAGE; \ 88 AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK; \ 89 } \ 90 } while (0) 91 92 #define AWT_ASSERT_NOT_APPKIT_THREAD \ 93 do { \ 94 if (pthread_main_np() != 0) { \ 95 AWT_THREAD_ASSERTS_ON_APPKIT_MESSAGE; \ 96 AWT_DEBUG_BUG_REPORT_MESSAGE; \ 97 AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK; \ 98 } \ 99 } while (0) 100 101 #define AWT_ASSERT_ANY_THREAD 102 103 #endif /* AWT_THREAD_ASSERTS_MESSAGES */ 104 105 #ifdef AWT_THREAD_ASSERTS_WAIT 106 107 #define AWT_ASSERT_APPKIT_THREAD \ 108 do { \ 109 while (pthread_main_np() == 0) {} \ 110 } while (0) 111 112 #define AWT_ASSERT_NOT_APPKIT_THREAD \ 113 do { \ 114 while (pthread_main_np() != 0) {} \ 115 } while (0) 116 117 #define AWT_ASSERT_ANY_THREAD 118 119 #endif /* AWT_THREAD_ASSERTS_WAIT */ 120 121 #else /* AWT_THREAD_ASSERTS */ 122 123 #define AWT_ASSERT_APPKIT_THREAD do {} while (0) 124 #define AWT_ASSERT_NOT_APPKIT_THREAD do {} while (0) 125 #define AWT_ASSERT_ANY_THREAD 126 127 #endif /* AWT_THREAD_ASSERTS */ 128 // -------------------------------------------------------------------------- 129 130 // This tracks if we are current inside of a performOnMainThread that is both waiting and in the AWTRunLoopMode 131 extern BOOL sInPerformFromJava; 132 133 // This is an empty Obj-C object just so that -performSelectorOnMainThread 134 // can be used, and to use the Obj-C +initialize feature. 135 __attribute__((visibility("default"))) 136 @interface ThreadUtilities : NSObject { } 137 138 + (JNIEnv*)getJNIEnv; 139 + (JNIEnv*)getJNIEnvUncached; 140 141 + (void)performOnMainThread:(SEL)aSelector onObject:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait awtMode:(BOOL)inAWT; 142 + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block; 143 @end 144 145 void OSXAPP_SetJavaVM(JavaVM *vm); 146 147 #endif /* __THREADUTILITIES_H */ | 81 #endif /* AWT_THREAD_ASSERTS_ENV_ASSERT */ 82 83 #define AWT_ASSERT_APPKIT_THREAD \ 84 do { \ 85 if (pthread_main_np() == 0) { \ 86 AWT_THREAD_ASSERTS_NOT_APPKIT_MESSAGE; \ 87 AWT_DEBUG_BUG_REPORT_MESSAGE; \ 88 AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK; \ 89 } \ 90 } while (0) 91 92 #define AWT_ASSERT_NOT_APPKIT_THREAD \ 93 do { \ 94 if (pthread_main_np() != 0) { \ 95 AWT_THREAD_ASSERTS_ON_APPKIT_MESSAGE; \ 96 AWT_DEBUG_BUG_REPORT_MESSAGE; \ 97 AWT_THREAD_ASSERTS_ENV_ASSERT_CHECK; \ 98 } \ 99 } while (0) 100 101 #endif /* AWT_THREAD_ASSERTS_MESSAGES */ 102 103 #ifdef AWT_THREAD_ASSERTS_WAIT 104 105 #define AWT_ASSERT_APPKIT_THREAD \ 106 do { \ 107 while (pthread_main_np() == 0) {} \ 108 } while (0) 109 110 #define AWT_ASSERT_NOT_APPKIT_THREAD \ 111 do { \ 112 while (pthread_main_np() != 0) {} \ 113 } while (0) 114 115 #endif /* AWT_THREAD_ASSERTS_WAIT */ 116 117 #else /* AWT_THREAD_ASSERTS */ 118 119 #define AWT_ASSERT_APPKIT_THREAD do {} while (0) 120 #define AWT_ASSERT_NOT_APPKIT_THREAD do {} while (0) 121 122 #endif /* AWT_THREAD_ASSERTS */ 123 // -------------------------------------------------------------------------- 124 125 // This tracks if we are current inside of a performOnMainThread that is both waiting and in the AWTRunLoopMode 126 extern BOOL sInPerformFromJava; 127 128 // This is an empty Obj-C object just so that -performSelectorOnMainThread 129 // can be used, and to use the Obj-C +initialize feature. 130 __attribute__((visibility("default"))) 131 @interface ThreadUtilities : NSObject { } 132 133 + (JNIEnv*)getJNIEnv; 134 + (JNIEnv*)getJNIEnvUncached; 135 136 + (void)performOnMainThread:(SEL)aSelector onObject:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait awtMode:(BOOL)inAWT; 137 138 //Wrappers for the corresponding JNFRunLoop methods with a check for main thread 139 + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block; 140 + (void)performOnMainThread:(SEL)aSelector on:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait; 141 @end 142 143 void OSXAPP_SetJavaVM(JavaVM *vm); 144 145 #endif /* __THREADUTILITIES_H */ |