static int 
eventUnblockJavaThread(
        JVMSPI_BlockedThreadInfo *blocked_threads,
        int blocked_threads_count, unsigned int waitingFor,
        int descriptor, int status)
{
    /*
     * IMPL NOTE: this functionality is similar to midp_thread_signal_list. 
     * It differs in that it reports to the caller whether a thread was
     * unblocked. This is a poor interface and should be removed. However,
     * the coupling with Push needs to be resolved first. In addition,
     * freeing of pResult here seems unsafe. Management of pResult needs
     * to be revisited.
     */
    int i;
    MidpReentryData* pThreadReentryData;

    for (i = 0; i < blocked_threads_count; i++) {
        pThreadReentryData =
            (MidpReentryData*)(blocked_threads[i].reentry_data);

        if (pThreadReentryData != ADDR_ZERO 
                && pThreadReentryData->descriptor == descriptor 
                && pThreadReentryData->waitingFor == waitingFor) {
            pThreadReentryData->status = status;
            midp_thread_unblock(blocked_threads[i].thread_id);
            return 1;
        }
    }

    return 0;
}
/**
 * Unblocks Java thread that monitors specified event queue.
 *
 * @param queueId queue ID
 */
static void unblockMonitorThread(jint queueId) {
    EventQueue* pEventQueue;
    jint isolateId;
    JVMSPI_ThreadID thread;
    
    GET_EVENT_QUEUE_BY_ID(pEventQueue, queueId);

    if (IS_ISOLATE_QUEUE(queueId)) {
        /*
         * 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.
         */
        isolateId = QUEUE_ID_TO_ISOLATE_ID(queueId);
        thread = SNI_GetSpecialThread(isolateId);
        if (thread != NULL) {
            midp_thread_unblock(thread);
        } else {
            REPORT_CRIT(LC_CORE,
                "StoreMIDPEventInVmThread: cannot find "
                "native event monitor thread");
        }
    } else {
        /* Unblock thread in the normal (slower) way */
        midp_thread_signal(EVENT_QUEUE_SIGNAL, queueId, 0);
    }

    pEventQueue->isMonitorBlocked = KNI_FALSE;    
}
static void
findAndUnblockHandle(int handle) {
    JVMSPI_ThreadID id = findBlockedHandle(handle);
    if (id != 0) {
        midp_thread_unblock(id);
    }
}
Beispiel #4
0
/*
 * See jsr205_mms_listeners.h for documentation
 */
WMA_STATUS jsr205_mms_unblock_thread(int handle, int waitingFor) {
    JVMSPI_ThreadID id = getBlockedThreadFromHandle((long)handle, waitingFor);
    if (id != 0) {
        midp_thread_unblock(id);
        return WMA_OK;
    }

    return WMA_ERR;
}
Beispiel #5
0
/*
 * See jsr120_cbs_listeners.h for documentation
 */
WMA_STATUS jsr120_cbs_unblock_thread(jint handle, jint waitingFor) {
    JVMSPI_ThreadID id =
        jsr120_cbs_get_blocked_thread_from_handle((long)handle, waitingFor);
    if (id != 0) {
	midp_thread_unblock(id);
	return WMA_OK;
    }

    return WMA_ERR;
}
Beispiel #6
0
/*
 * See wma_mms_listeners.h for documentation
 */
void jsr205_mms_message_sent_notifier() {

    /*
     * An MMS message has been sent. So unblock thread
	* blocked on WMA_MMS_WRITE_SIGNAL.
	*/
    JVMSPI_ThreadID id = getBlockedThreadFromSignal(WMA_MMS_WRITE_SIGNAL);

    if (id != 0) {
	midp_thread_unblock(id);
    }
}
Beispiel #7
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();
}
/**
 * Find and unblock all Java threads based on what the thread is waiting
 * for and which descriptor it is waiting on.
 *
 * @param blocked_threads list of blocked threads
 * @param blocked_threads_count number of blocked threads in the list
 * @param waitingFor used to match MidpReentryData.waitingFor
 * @param descriptor used to match MidpReentryData.descriptor
 * @param status the value stored into MidpReentryData.status for every
 *               thread that is unblocked
 */
void
midp_thread_signal_list(
    JVMSPI_BlockedThreadInfo *blocked_threads,
    int blocked_threads_count, midpSignalType waitingFor,
    int descriptor, int status)
{
    int i;
    MidpReentryData* pThreadReentryData;

    for (i = 0; i < blocked_threads_count; i++) {
        pThreadReentryData =
            (MidpReentryData*)(blocked_threads[i].reentry_data);

        if (pThreadReentryData != NULL
                && pThreadReentryData->descriptor == descriptor
                && pThreadReentryData->waitingFor == waitingFor) {
            pThreadReentryData->status = status;
            midp_thread_unblock(blocked_threads[i].thread_id);
        }
    }
}
Beispiel #9
0
/**
 *  The function unblocks threads waiting for Transaction Store
 */
void unlock() {
    int i, n;
    JVMSPI_BlockedThreadInfo *blocked_threads;
    MidpReentryData* pThreadReentryData;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    if ((locked == KNI_TRUE) && 
            (getStorageOpenFlag(thisObject)->isOpen == KNI_TRUE)) {
        blocked_threads = SNI_GetBlockedThreads(&n);
        getStorageOpenFlag(thisObject)->isOpen = KNI_FALSE;
        locked = KNI_FALSE;
        for (i = 0; i < n; i++) {

            pThreadReentryData =
                (MidpReentryData*)(blocked_threads[i].reentry_data);

            if (pThreadReentryData == NULL) {
                continue;
            }
     
            if (pThreadReentryData->waitingFor != 
                    PAYMENT_TRANSACTION_STORE_SIGNAL) {
                continue;
            }

            pThreadReentryData->status = KNI_TRUE;
 
            midp_thread_unblock(blocked_threads[i].thread_id);
        }

    }

    KNI_EndHandles();
}