void tested_thread_wait_ended(tested_thread_sturct_t *tts) {
    int i;
     
    i = 0;
    while (hysem_wait_timed(tts->ended, MAX_TIME_TO_WAIT, 0) == TM_ERROR_TIMEOUT) {
        i++;
        log_info("Thread %i hasn't ended for %i milliseconds",
            tts->my_index, (i * MAX_TIME_TO_WAIT));
    }
    hysem_post(tts->ended);
}
示例#2
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