/**
 * Blocks the Java event thread until an event has been queued and returns
 * that event and the number of events still in the queue.
 *
 * @param event An empty event to be filled in if there is a queued
 *              event.
 *
 * @return number of events waiting in the native queue
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_events_NativeEventMonitor_waitForNativeEvent(void) {
    jint queueId;
    int eventsPending;
    EventQueue* pEventQueue;

    queueId = KNI_GetParameterAsInt(2);
    eventsPending = readNativeEventCommon(queueId);
    if (eventsPending != -1) {
        /* event was read, and more may be pending */
        KNI_ReturnInt(eventsPending);
    }

    GET_EVENT_QUEUE_BY_ID(pEventQueue, queueId);

    if (pEventQueue->isMonitorBlocked) {
        /*
         * ASSERT: we are about to block, so the state must not indicate
         * that a monitor thread is already blocked.
         */
        REPORT_CRIT(LC_CORE,
            "Assertion failed: NativeEventMonitor.waitForNativeEvent "
            "called when Java thread already blocked");
    }

    blockMonitorThread(queueId);

    KNI_ReturnInt(0);
}
/**
 * Reads a native event without blocking.
 *
 * @param event An empty event to be filled in if there is a queued
 *              event.
 * @return <tt>true</tt> if an event was read, otherwise <tt>false</tt>
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
Java_com_sun_midp_events_NativeEventMonitor_readNativeEvent(void) {
    jint queueId;

    queueId = KNI_GetParameterAsInt(2);

    KNI_ReturnBoolean(readNativeEventCommon(queueId) != -1);
}
Пример #3
0
/**
 * Reads a native event without blocking.
 *
 * @param event An empty event to be filled in if there is a queued
 *              event.
 * @return <tt>true</tt> if an event was read, otherwise <tt>false</tt>
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
Java_com_sun_midp_events_NativeEventMonitor_readNativeEvent(void) {
    jint isolateId;

    isolateId = getCurrentIsolateId();

    KNI_ReturnBoolean(readNativeEventCommon(isolateId) != -1);
}
Пример #4
0
/**
 * Blocks the Java event thread until an event has been queued and returns
 * that event and the number of events still in the queue.
 *
 * @param event An empty event to be filled in if there is a queued
 *              event.
 *
 * @return number of events waiting in the native queue
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_events_NativeEventMonitor_waitForNativeEvent(void) {
    jint isolateId;
    int eventsPending;
    EventQueue* pEventQueue;

    isolateId = getCurrentIsolateId();
    eventsPending = readNativeEventCommon(isolateId);
    if (eventsPending != -1) {
        /* event was read, and more may be pending */
        KNI_ReturnInt(eventsPending);
    }

    pEventQueue = getIsolateEventQueue(isolateId);

    if (pEventQueue->isMonitorBlocked) {
        /*
         * ASSERT: we are about to block, so the state must not indicate
         * that a monitor thread is already blocked.
         */
        REPORT_CRIT(LC_CORE,
            "Assertion failed: NativeEventMonitor.waitForNativeEvent "
            "called when Java thread already blocked");
    }

    /*
     * Block the event processing thread.  To speed up unblocking the
     * event monitor thread, this thread is saved as the "special" thread
     * of an Isolate to avoid having to search the entire list of threads.
     */
    SNI_SetSpecialThread(isolateId);
    SNI_BlockThread();
    pEventQueue->isMonitorBlocked = KNI_TRUE;

    KNI_ReturnInt(0);
}