1 /*
2 * Copyright (c) 2002, 2015, 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
563 if (timeout_control == TIMEOUT_TIMEDOUT) {
564 curPollTimeout += ((curPollTimeout>>2) + 1);
565 curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout);
566 if((int)curPollTimeout > AWT_POLL_THRESHOLD || (int)curPollTimeout == AWT_POLL_BLOCK)
567 curPollTimeout = AWT_POLL_BLOCK;
568 } else if (timeout_control == TIMEOUT_EVENTS) {
569 curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, 1);
570 }
571 break;
572 }
573 }
574
575 /*
576 * Gets the best timeout for the next call to poll().
577 *
578 * @param nextTaskTime -1, if there are no tasks; next time when
579 * timeout task needs to be run, in millis(of currentTimeMillis)
580 */
581 static uint32_t get_poll_timeout(jlong nextTaskTime)
582 {
583 uint32_t ret_timeout;
584 uint32_t timeout;
585 uint32_t taskTimeout;
586 uint32_t flushTimeout;
587
588 jlong curTime = awtJNI_TimeMillis();
589 timeout = curPollTimeout;
590 switch(awt_poll_alg) {
591 case AWT_POLL_AGING_SLOW:
592 case AWT_POLL_AGING_FAST:
593 taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime));
594 flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT;
595
596 PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime);
597
598 // Adjust timeout to flush_time and task_time
599 ret_timeout = min(flushTimeout, min(taskTimeout, timeout));
600 if((int)curPollTimeout == AWT_POLL_BLOCK)
601 ret_timeout = AWT_POLL_BLOCK;
602 break;
603
743 PRINT("f1\n");
744 AWT_LOCK();
745 XFlush(awt_display);
746 awt_last_flush_time = curTime;
747 AWT_NOFLUSH_UNLOCK();
748 } else {
749 awt_next_flush_time = next_flush_time;
750 PRINT("f2\n");
751 wakeUp();
752 }
753 }
754 }
755
756
757 /**
758 * Wakes-up poll() in performPoll
759 */
760 static void wakeUp() {
761 static char wakeUp_char = 'p';
762 if (!isMainThread() && awt_pipe_inited) {
763 write ( AWT_WRITEPIPE, &wakeUp_char, 1 );
764 }
765 }
766
767
768 /* ========================== End poll section ================================= */
769
770 /*
771 * Class: java_awt_KeyboardFocusManager
772 * Method: initIDs
773 * Signature: ()V
774 */
775 JNIEXPORT void JNICALL
776 Java_java_awt_KeyboardFocusManager_initIDs
777 (JNIEnv *env, jclass cls)
778 {
779 }
780
781 /*
782 * Class: sun_awt_X11_XToolkit
783 * Method: getEnv
|
1 /*
2 * Copyright (c) 2002, 2016, 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
563 if (timeout_control == TIMEOUT_TIMEDOUT) {
564 curPollTimeout += ((curPollTimeout>>2) + 1);
565 curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout);
566 if((int)curPollTimeout > AWT_POLL_THRESHOLD || (int)curPollTimeout == AWT_POLL_BLOCK)
567 curPollTimeout = AWT_POLL_BLOCK;
568 } else if (timeout_control == TIMEOUT_EVENTS) {
569 curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, 1);
570 }
571 break;
572 }
573 }
574
575 /*
576 * Gets the best timeout for the next call to poll().
577 *
578 * @param nextTaskTime -1, if there are no tasks; next time when
579 * timeout task needs to be run, in millis(of currentTimeMillis)
580 */
581 static uint32_t get_poll_timeout(jlong nextTaskTime)
582 {
583 uint32_t ret_timeout = 0;
584 uint32_t timeout;
585 uint32_t taskTimeout;
586 uint32_t flushTimeout;
587
588 jlong curTime = awtJNI_TimeMillis();
589 timeout = curPollTimeout;
590 switch(awt_poll_alg) {
591 case AWT_POLL_AGING_SLOW:
592 case AWT_POLL_AGING_FAST:
593 taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime));
594 flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT;
595
596 PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime);
597
598 // Adjust timeout to flush_time and task_time
599 ret_timeout = min(flushTimeout, min(taskTimeout, timeout));
600 if((int)curPollTimeout == AWT_POLL_BLOCK)
601 ret_timeout = AWT_POLL_BLOCK;
602 break;
603
743 PRINT("f1\n");
744 AWT_LOCK();
745 XFlush(awt_display);
746 awt_last_flush_time = curTime;
747 AWT_NOFLUSH_UNLOCK();
748 } else {
749 awt_next_flush_time = next_flush_time;
750 PRINT("f2\n");
751 wakeUp();
752 }
753 }
754 }
755
756
757 /**
758 * Wakes-up poll() in performPoll
759 */
760 static void wakeUp() {
761 static char wakeUp_char = 'p';
762 if (!isMainThread() && awt_pipe_inited) {
763 size_t bytesWritten = write ( AWT_WRITEPIPE, &wakeUp_char, 1 ); //bytesWritten is unused
764 }
765 }
766
767
768 /* ========================== End poll section ================================= */
769
770 /*
771 * Class: java_awt_KeyboardFocusManager
772 * Method: initIDs
773 * Signature: ()V
774 */
775 JNIEXPORT void JNICALL
776 Java_java_awt_KeyboardFocusManager_initIDs
777 (JNIEnv *env, jclass cls)
778 {
779 }
780
781 /*
782 * Class: sun_awt_X11_XToolkit
783 * Method: getEnv
|