0N/A/*
3261N/A * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * Common AWT definitions
0N/A */
0N/A
0N/A#ifndef _AWT_
0N/A#define _AWT_
0N/A
0N/A#include "jvm.h"
0N/A#include "jni_util.h"
0N/A#include "debug_util.h"
0N/A
0N/A#ifndef HEADLESS
0N/A#include <X11/Intrinsic.h>
0N/A#endif /* !HEADLESS */
0N/A
0N/A
0N/A/* The JVM instance: defined in awt_MToolkit.c */
0N/Aextern JavaVM *jvm;
0N/A
0N/Aextern jclass tkClass;
0N/Aextern jmethodID awtLockMID;
0N/Aextern jmethodID awtUnlockMID;
0N/Aextern jmethodID awtWaitMID;
0N/Aextern jmethodID awtNotifyMID;
0N/Aextern jmethodID awtNotifyAllMID;
0N/Aextern jboolean awtLockInited;
0N/A
0N/A/* Perform sanity and consistency checks on AWT locking */
0N/A#ifdef DEBUG
0N/A#define DEBUG_AWT_LOCK
0N/A#endif
0N/A
0N/A/*
0N/A * The following locking primitives should be defined
0N/A *
0N/A#define AWT_LOCK()
0N/A#define AWT_NOFLUSH_UNLOCK()
0N/A#define AWT_WAIT(tm)
0N/A#define AWT_NOTIFY()
0N/A#define AWT_NOTIFY_ALL()
0N/A */
0N/A
0N/A/*
0N/A * Convenience macros based on AWT_NOFLUSH_UNLOCK
0N/A */
0N/Aextern void awt_output_flush();
0N/A#define AWT_UNLOCK() AWT_FLUSH_UNLOCK()
0N/A#define AWT_FLUSH_UNLOCK() do { \
0N/A awt_output_flush(); \
0N/A AWT_NOFLUSH_UNLOCK(); \
0N/A} while (0)
0N/A
0N/A#define AWT_LOCK_IMPL() \
0N/A (*env)->CallStaticVoidMethod(env, tkClass, awtLockMID)
0N/A#define AWT_NOFLUSH_UNLOCK_IMPL() \
0N/A (*env)->CallStaticVoidMethod(env, tkClass, awtUnlockMID)
0N/A#define AWT_WAIT_IMPL(tm) \
0N/A (*env)->CallStaticVoidMethod(env, tkClass, awtWaitMID, (jlong)(tm))
0N/A#define AWT_NOTIFY_IMPL() \
0N/A (*env)->CallStaticVoidMethod(env, tkClass, awtNotifyMID)
0N/A#define AWT_NOTIFY_ALL_IMPL() \
0N/A (*env)->CallStaticVoidMethod(env, tkClass, awtNotifyAllMID)
0N/A
0N/A/*
0N/A * Unfortunately AWT_LOCK debugging does not work with XAWT due to mixed
0N/A * Java/C use of AWT lock.
0N/A */
0N/A#if defined(DEBUG_AWT_LOCK) && !defined(XAWT)
0N/Aextern int awt_locked;
0N/Aextern char *lastF;
0N/Aextern int lastL;
0N/A
0N/A#define AWT_LOCK() do { \
0N/A if (!awtLockInited) { \
0N/A jio_fprintf(stderr, "AWT lock error, awt_lock is null\n"); \
0N/A } \
0N/A if (awt_locked < 0) { \
0N/A jio_fprintf(stderr, \
0N/A "AWT lock error (%s,%d) (last held by %s,%d) %d\n", \
0N/A __FILE__, __LINE__, lastF, lastL, awt_locked); \
0N/A } \
0N/A lastF = __FILE__; \
0N/A lastL = __LINE__; \
0N/A AWT_LOCK_IMPL(); \
0N/A ++awt_locked; \
0N/A} while (0)
0N/A
0N/A#define AWT_NOFLUSH_UNLOCK() do { \
0N/A lastF = ""; \
0N/A lastL = -1; \
0N/A if (awt_locked < 1) { \
0N/A jio_fprintf(stderr, "AWT unlock error (%s,%d,%d)\n", \
0N/A __FILE__, __LINE__, awt_locked); \
0N/A } \
0N/A --awt_locked; \
0N/A AWT_NOFLUSH_UNLOCK_IMPL(); \
0N/A} while (0)
0N/A
0N/A#define AWT_WAIT(tm) do { \
0N/A int old_lockcount = awt_locked; \
0N/A if (awt_locked < 1) { \
0N/A jio_fprintf(stderr, "AWT wait error (%s,%d,%d)\n", \
0N/A __FILE__, __LINE__, awt_locked); \
0N/A } \
0N/A awt_locked = 0; \
0N/A AWT_WAIT_IMPL(tm); \
0N/A awt_locked = old_lockcount; \
0N/A} while (0)
0N/A
0N/A#define AWT_NOTIFY() do { \
0N/A if (awt_locked < 1) { \
0N/A jio_fprintf(stderr, "AWT notify error (%s,%d,%d)\n", \
0N/A __FILE__, __LINE__, awt_locked); \
0N/A } \
0N/A AWT_NOTIFY_IMPL(); \
0N/A} while(0)
0N/A
0N/A#define AWT_NOTIFY_ALL() do { \
0N/A if (awt_locked < 1) { \
0N/A jio_fprintf(stderr, "AWT notify all error (%s,%d,%d)\n", \
0N/A __FILE__, __LINE__, awt_locked); \
0N/A } \
0N/A AWT_NOTIFY_ALL_IMPL(); \
0N/A} while (0)
0N/A
0N/A#else
0N/A
0N/A#define AWT_LOCK() AWT_LOCK_IMPL()
0N/A#define AWT_NOFLUSH_UNLOCK() AWT_NOFLUSH_UNLOCK_IMPL()
0N/A#define AWT_WAIT(tm) AWT_WAIT_IMPL(tm)
0N/A#define AWT_NOTIFY() AWT_NOTIFY_IMPL()
0N/A#define AWT_NOTIFY_ALL() AWT_NOTIFY_ALL_IMPL()
0N/A
0N/A#endif /* DEBUG_AWT_LOCK && !XAWT */
0N/A
0N/A#ifndef HEADLESS
2859N/Aextern Display *awt_display; /* awt_GraphicsEnv.c */
2859N/Aextern Boolean awt_ModLockIsShiftLock; /* XToolkit.c */
0N/A#endif /* !HEADLESS */
0N/A
0N/A#endif /* ! _AWT_ */