/** * Blocks Java thread that monitors specified event queue. * * @param queueId queue ID */ static void blockMonitorThread(jint queueId) { EventQueue* pEventQueue; jint isolateId; GET_EVENT_QUEUE_BY_ID(pEventQueue, queueId); if (IS_ISOLATE_QUEUE(queueId)) { /* * 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. */ isolateId = QUEUE_ID_TO_ISOLATE_ID(queueId); SNI_SetSpecialThread(isolateId); SNI_BlockThread(); } else { /* Block thread in the normal way */ midp_thread_wait(EVENT_QUEUE_SIGNAL, queueId, 0); } pEventQueue->isMonitorBlocked = KNI_TRUE; }
/** * 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); }