337
338 // Includes
339
340 #include <sys/time.h>
341 #include <limits.h>
342 #include <locale.h>
343 #include <pthread.h>
344
345 #include <dlfcn.h>
346 #include <fcntl.h>
347
348 #include <poll.h>
349 #ifndef POLLRDNORM
350 #define POLLRDNORM POLLIN
351 #endif
352
353 // Prototypes
354
355 static void waitForEvents(JNIEnv *, jlong);
356 static void awt_pipe_init();
357 static void processOneEvent(XtInputMask iMask);
358 static Boolean performPoll(JNIEnv *, jlong);
359 static void wakeUp();
360 static void update_poll_timeout(int timeout_control);
361 static uint32_t get_poll_timeout(jlong nextTaskTime);
362
363 // Defines
364
365 #ifndef bzero
366 #define bzero(a,b) memset(a, 0, b)
367 #endif
368
369 #define AWT_POLL_BUFSIZE 100 /* bytes */
370 #define AWT_READPIPE (awt_pipe_fds[0])
371 #define AWT_WRITEPIPE (awt_pipe_fds[1])
372
373 #ifdef JAVASE_EMBEDDED
374 #define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)4000000000) /* milliseconds */
375 #else
376 #define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)500) /* milliseconds */
377 #endif
597 PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime);
598
599 // Adjust timeout to flush_time and task_time
600 ret_timeout = min(flushTimeout, min(taskTimeout, timeout));
601 if((int)curPollTimeout == AWT_POLL_BLOCK)
602 ret_timeout = AWT_POLL_BLOCK;
603 break;
604
605 case AWT_POLL_FALSE:
606 ret_timeout = (nextTaskTime > curTime) ?
607 (nextTaskTime - curTime) :
608 ((nextTaskTime == -1) ? -1 : 0);
609 break;
610 }
611
612 return ret_timeout;
613
614 } /* get_poll_timeout() */
615
616 /*
617 * Waits for X/Xt events to appear on the pipe. Returns only when
618 * it is likely (but not definite) that there are events waiting to
619 * be processed.
620 *
621 * This routine also flushes the outgoing X queue, when the
622 * awt_next_flush_time has been reached.
623 *
624 * If fdAWTPipe is greater or equal than zero the routine also
625 * checks if there are events pending on the putback queue.
626 */
627 void
628 waitForEvents(JNIEnv *env, jlong nextTaskTime) {
629 if (performPoll(env, nextTaskTime)
630 && (awt_next_flush_time > 0)
631 && (awtJNI_TimeMillis() >= awt_next_flush_time)) {
632
633 XFlush(awt_display);
634 awt_last_flush_time = awt_next_flush_time;
635 awt_next_flush_time = 0LL;
636 }
637 } /* waitForEvents() */
|
337
338 // Includes
339
340 #include <sys/time.h>
341 #include <limits.h>
342 #include <locale.h>
343 #include <pthread.h>
344
345 #include <dlfcn.h>
346 #include <fcntl.h>
347
348 #include <poll.h>
349 #ifndef POLLRDNORM
350 #define POLLRDNORM POLLIN
351 #endif
352
353 // Prototypes
354
355 static void waitForEvents(JNIEnv *, jlong);
356 static void awt_pipe_init();
357 static Boolean performPoll(JNIEnv *, jlong);
358 static void wakeUp();
359 static void update_poll_timeout(int timeout_control);
360 static uint32_t get_poll_timeout(jlong nextTaskTime);
361
362 // Defines
363
364 #ifndef bzero
365 #define bzero(a,b) memset(a, 0, b)
366 #endif
367
368 #define AWT_POLL_BUFSIZE 100 /* bytes */
369 #define AWT_READPIPE (awt_pipe_fds[0])
370 #define AWT_WRITEPIPE (awt_pipe_fds[1])
371
372 #ifdef JAVASE_EMBEDDED
373 #define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)4000000000) /* milliseconds */
374 #else
375 #define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)500) /* milliseconds */
376 #endif
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
604 case AWT_POLL_FALSE:
605 ret_timeout = (nextTaskTime > curTime) ?
606 (nextTaskTime - curTime) :
607 ((nextTaskTime == -1) ? -1 : 0);
608 break;
609 }
610
611 return ret_timeout;
612
613 } /* get_poll_timeout() */
614
615 /*
616 * Waits for X events to appear on the pipe. Returns only when
617 * it is likely (but not definite) that there are events waiting to
618 * be processed.
619 *
620 * This routine also flushes the outgoing X queue, when the
621 * awt_next_flush_time has been reached.
622 *
623 * If fdAWTPipe is greater or equal than zero the routine also
624 * checks if there are events pending on the putback queue.
625 */
626 void
627 waitForEvents(JNIEnv *env, jlong nextTaskTime) {
628 if (performPoll(env, nextTaskTime)
629 && (awt_next_flush_time > 0)
630 && (awtJNI_TimeMillis() >= awt_next_flush_time)) {
631
632 XFlush(awt_display);
633 awt_last_flush_time = awt_next_flush_time;
634 awt_next_flush_time = 0LL;
635 }
636 } /* waitForEvents() */
|