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