| 1 | /* |
| 2 | * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved. |
| 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 | /* |
| 27 | * Common AWT definitions |
| 28 | */ |
| 29 | |
| 30 | #ifndef _AWT_ |
| 31 | #define _AWT_ |
| 32 | |
| 33 | #include "jvm.h" |
| 34 | #include "jni_util.h" |
| 35 | #include "debug_util.h" |
| 36 | |
| 37 | #if !defined(HEADLESS) && !defined(MACOSX) |
| 38 | #include <X11/Xlib.h> |
| 39 | #include <X11/Xutil.h> |
| 40 | typedef char Boolean; |
| 41 | #endif /* !HEADLESS && !MACOSX */ |
| 42 | |
| 43 | |
| 44 | /* The JVM instance: defined in awt_MToolkit.c */ |
| 45 | extern JavaVM *jvm; |
| 46 | |
| 47 | extern jclass tkClass; |
| 48 | extern jmethodID awtLockMID; |
| 49 | extern jmethodID awtUnlockMID; |
| 50 | extern jmethodID awtWaitMID; |
| 51 | extern jmethodID awtNotifyMID; |
| 52 | extern jmethodID awtNotifyAllMID; |
| 53 | extern jboolean awtLockInited; |
| 54 | |
| 55 | /* Perform sanity and consistency checks on AWT locking */ |
| 56 | #ifdef DEBUG |
| 57 | #define DEBUG_AWT_LOCK |
| 58 | #endif |
| 59 | |
| 60 | /* |
| 61 | * The following locking primitives should be defined |
| 62 | * |
| 63 | #define AWT_LOCK() |
| 64 | #define AWT_NOFLUSH_UNLOCK() |
| 65 | #define AWT_WAIT(tm) |
| 66 | #define AWT_NOTIFY() |
| 67 | #define AWT_NOTIFY_ALL() |
| 68 | */ |
| 69 | |
| 70 | /* |
| 71 | * Convenience macros based on AWT_NOFLUSH_UNLOCK |
| 72 | */ |
| 73 | extern void awt_output_flush(); |
| 74 | #define AWT_UNLOCK() AWT_FLUSH_UNLOCK() |
| 75 | #define AWT_FLUSH_UNLOCK() do { \ |
| 76 | awt_output_flush(); \ |
| 77 | AWT_NOFLUSH_UNLOCK(); \ |
| 78 | } while (0) |
| 79 | |
| 80 | #define AWT_UNLOCK_CHECK_EXCEPTION(env) \ |
| 81 | do { \ |
| 82 | AWT_UNLOCK(); \ |
| 83 | JNU_CHECK_EXCEPTION(env); \ |
| 84 | } while (0) |
| 85 | |
| 86 | #define AWT_LOCK_IMPL() \ |
| 87 | do { \ |
| 88 | (*env)->CallStaticVoidMethod(env, tkClass, awtLockMID); \ |
| 89 | if ((*env)->ExceptionCheck(env)) { \ |
| 90 | (*env)->ExceptionClear(env); \ |
| 91 | } \ |
| 92 | } while(0) |
| 93 | |
| 94 | #define AWT_NOFLUSH_UNLOCK_IMPL() \ |
| 95 | do { \ |
| 96 | jthrowable pendingException; \ |
| 97 | if ((pendingException = (*env)->ExceptionOccurred(env)) != NULL) { \ |
| 98 | (*env)->ExceptionClear(env); \ |
| 99 | } \ |
| 100 | (*env)->CallStaticVoidMethod(env, tkClass, awtUnlockMID); \ |
| 101 | if ((*env)->ExceptionCheck(env)) { \ |
| 102 | (*env)->ExceptionClear(env); \ |
| 103 | } \ |
| 104 | if (pendingException) { \ |
| 105 | (*env)->Throw(env, pendingException); \ |
| 106 | } \ |
| 107 | } while (0) |
| 108 | #define AWT_WAIT_IMPL(tm) \ |
| 109 | (*env)->CallStaticVoidMethod(env, tkClass, awtWaitMID, (jlong)(tm)) |
| 110 | #define AWT_NOTIFY_IMPL() \ |
| 111 | (*env)->CallStaticVoidMethod(env, tkClass, awtNotifyMID) |
| 112 | #define AWT_NOTIFY_ALL_IMPL() \ |
| 113 | (*env)->CallStaticVoidMethod(env, tkClass, awtNotifyAllMID) |
| 114 | |
| 115 | /* |
| 116 | * Unfortunately AWT_LOCK debugging does not work with XAWT due to mixed |
| 117 | * Java/C use of AWT lock. |
| 118 | */ |
| 119 | #define AWT_LOCK() AWT_LOCK_IMPL() |
| 120 | #define AWT_NOFLUSH_UNLOCK() AWT_NOFLUSH_UNLOCK_IMPL() |
| 121 | #define AWT_WAIT(tm) AWT_WAIT_IMPL(tm) |
| 122 | #define AWT_NOTIFY() AWT_NOTIFY_IMPL() |
| 123 | #define AWT_NOTIFY_ALL() AWT_NOTIFY_ALL_IMPL() |
| 124 | |
| 125 | #if !defined(HEADLESS) && !defined(MACOSX) |
| 126 | extern Display *awt_display; /* awt_GraphicsEnv.c */ |
| 127 | extern Boolean awt_ModLockIsShiftLock; /* XToolkit.c */ |
| 128 | #endif /* !HEADLESS && !MACOSX */ |
| 129 | |
| 130 | #endif /* ! _AWT_ */ |
| 131 | |