/**
 * Helper function used by StoreMIDPEventInVmThread. Enqueues an event 
 * to be processed by the Java event thread for a given event queue.
 *
 * @param event the event to enqueue
 * @queueID ID of the queue to enqueue event from
 */
static void StoreMIDPEventInVmThreadImp(MidpEvent event, jint queueId) {
    EventQueue* pEventQueue;

    GET_EVENT_QUEUE_BY_ID(pEventQueue, queueId);

    midp_logThreadId("StoreMIDPEventInVmThread");

    midp_waitAndLockEventQueue();

    if (pEventQueue->numEvents != MAX_EVENTS) {

        pEventQueue->events[pEventQueue->eventIn] = event;
        pEventQueue->eventIn++;
        if (pEventQueue->eventIn == MAX_EVENTS) {
            /* This is a circular queue, so start back at zero. */
            pEventQueue->eventIn = 0;
        }
      
        pEventQueue->numEvents++;

        if (pEventQueue->isMonitorBlocked) {
            unblockMonitorThread(queueId);
        }
    } else {
        /*
         * Ignore the event; there is no space to store it.
         * IMPL NOTE: this should be fixed, or it should be a fatal error; 
         * dropping an event can lead to a full system deadlock.
         */
        REPORT_CRIT1(LC_CORE,"**event queue %d full, dropping event",
                     queueId); 
    }

    midp_unlockEventQueue();

#if ENABLE_EVENT_SPYING
    if (queueId != gsEventSpyingQueueId) {
        GET_EVENT_QUEUE_BY_ID(pEventQueue, gsEventSpyingQueueId);
        if (pEventQueue->isActive && event.type != EVENT_QUEUE_SHUTDOWN) {
            if (0 == duplicateMIDPEventFields(&event)) {
                StoreMIDPEventInVmThreadImp(event, gsEventSpyingQueueId); 
            } else {
                REPORT_CRIT(LC_CORE, 
                        "StoreMIDPEventInVmThread: Out of memory.");
                return;
            }
        }
    }
#endif
}
示例#2
0
static void StoreMIDPEventInVmThreadImp(MidpEvent event, int isolateId) {
    EventQueue* pEventQueue;
    JVMSPI_ThreadID thread;

    pEventQueue = getIsolateEventQueue(isolateId);

    midp_logThreadId("StoreMIDPEventInVmThread");

    midp_waitAndLockEventQueue();

    if (pEventQueue->numEvents != MAX_EVENTS) {

        pEventQueue->events[pEventQueue->eventIn] = event;
        pEventQueue->eventIn++;
        if (pEventQueue->eventIn == MAX_EVENTS) {
            /* This is a circular queue, so start back at zero. */
            pEventQueue->eventIn = 0;
        }
      
        pEventQueue->numEvents++;

        if (pEventQueue->isMonitorBlocked) {
            /*
             * The event monitor thread has been saved as the "special" thread
             * of this particular isolate in order to avoid having to search
             * the entire list of threads.
             */
            thread = SNI_GetSpecialThread(isolateId);
            if (thread != NULL) {
                midp_thread_unblock(thread);
                pEventQueue->isMonitorBlocked = KNI_FALSE;
            } else {
                REPORT_CRIT(LC_CORE,
                    "StoreMIDPEventInVmThread: cannot find "
                    "native event monitor thread");
            }
        }
    } else {
        /*
         * Ignore the event; there is no space to store it.
         * IMPL NOTE: this should be fixed, or it should be a fatal error; 
         * dropping an event can lead to a full system deadlock.
         */
        REPORT_CRIT1(LC_CORE,"**event queue %d full, dropping event",
                     isolateId); 
    }

    midp_unlockEventQueue();
}