/** * Enqueues an event to be processed by the Java event thread for a given * Isolate, or for all isolates queues if isolateId is -1. * Only safe to call from VM thread. * Any other threads should call StoreMIDPEvent. * * @param event The event to enqueue. * * @param isolateId ID of an Isolate * -1 for broadcast to all isolates * 0 for SVM mode */ void StoreMIDPEventInVmThread(MidpEvent event, int isolateId) { jint queueId = -1; if( -1 != isolateId ) { queueId = ISOLATE_ID_TO_QUEUE_ID(isolateId); StoreMIDPEventInVmThreadImp(event, queueId); } else { #if ENABLE_MULTIPLE_ISOLATES EventQueue* pEventQueue; StoreMIDPEventInVmThreadImp(event, 1); for (isolateId = 2; isolateId <= gsMaxIsolates; isolateId++) { queueId = ISOLATE_ID_TO_QUEUE_ID(isolateId); GET_EVENT_QUEUE_BY_ID(pEventQueue, queueId); /* * Broadcast only for active queues to avoid overflowing * inactive queues that no one is currently reading events from */ if (pEventQueue->isActive) { if (0 != duplicateMIDPEventFields(&event)) { REPORT_CRIT(LC_CORE, "StoreMIDPEventInVmThread: " "Out of memory."); return; } StoreMIDPEventInVmThreadImp(event, queueId); } } #else StoreMIDPEventInVmThreadImp(event, 0); #endif } }
/** * Enqueues an event to be processed by the Java event thread for a given * Isolate, or all isolates if isolateId is -1. * Only safe to call from VM thread. * Any other threads should call StoreMIDPEvent. * * @param event The event to enqueue. * * @param isolateId ID of an Isolate * -1 for broadcast to all isolates * 0 for SVM mode */ void StoreMIDPEventInVmThread(MidpEvent event, int isolateId) { if( -1 != isolateId ) { StoreMIDPEventInVmThreadImp(event, isolateId); } else { for (isolateId = 0; isolateId < MAX_ISOLATES; ++isolateId) StoreMIDPEventInVmThreadImp(event, isolateId); } }
/** * 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 }
/** * Sends a shutdown event to the event queue of the current Isolate. * */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_events_EventQueue_sendShutdownEvent0(void) { MidpEvent event; jint queueId; /* Initialize the event with just the SHUTDOWN type */ MIDP_EVENT_INITIALIZE(event); event.type = EVENT_QUEUE_SHUTDOWN; /* Send the shutdown event. */ queueId = KNI_GetParameterAsInt(1); StoreMIDPEventInVmThreadImp(event, queueId); KNI_ReturnVoid(); }