예제 #1
0
IDATA VMCALL hythread_set_thread_stop_callback(hythread_t thread,
    tm_thread_event_callback_proc stop_callback)
{
    IDATA status = hythread_set_safepoint_callback(thread, stop_callback);

    while (thread->suspend_count > 0) {
        apr_atomic_dec32((volatile apr_uint32_t *)
            &thread->suspend_count);
        apr_atomic_dec32((volatile apr_uint32_t *)
            &thread->request);
    }

    // if there is no competition, it would be 1, but if someone else is
    // suspending the same thread simultaneously, it could be greater than 1
    // if safepoint callback isn't set it could be equal to 0.
    //
    // The following assertion may be false because at each time
    // one of the conditions is true, and the other is false, but
    // when checking the whole condition it may be failse in the result.
    // assert(thread->request > 0 || thread->safepoint_callback == NULL);

    // notify the thread that it may wake up now,
    // so that it would eventually reach exception safepoint
    // and execute callback
    hysem_post(thread->resume_event);

    if (thread->state &
            (TM_THREAD_STATE_SLEEPING | TM_THREAD_STATE_WAITING_WITH_TIMEOUT
                | TM_THREAD_STATE_WAITING | TM_THREAD_STATE_IN_MONITOR_WAIT
                | TM_THREAD_STATE_WAITING_INDEFINITELY | TM_THREAD_STATE_PARKED))
    {
        // This is needed for correct stopping of a thread blocked on monitor_wait.
        // The thread needs some flag to exit its waiting loop.
        // We piggy-back on interrupted status. A correct exception from TLS
        // will be thrown because the check of exception status on leaving
        // JNI frame comes before checking return status in Object.wait().
        // Interrupted status will be cleared by function returning TM_ERROR_INTERRUPT.
        // (though, in case of parked thread, it will not be cleared)
        hythread_interrupt(thread);
    }
    return status;
} // hythread_set_thread_stop_callback
예제 #2
0
/**
 * Interrupt a <code>thread</code>.
 *
 * If the <code>thread</code>is currently blocked (i.e. waiting on a monitor_wait or sleeping)
 * resume the <code>thread</code>and cause it to return from the blocking function with
 * TM_THREAD_INTERRUPTED.
 *
 * @param[in] java_thread a thread to be interrupted
 * @sa java.lang.Thread.interrupt()
 */
IDATA VMCALL jthread_interrupt(jthread java_thread)
{
    hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
    hythread_interrupt(tm_native_thread);
    return TM_ERROR_NONE;
} // jthread_interrupt