/**
 * Waits on a conditional, handling interruptions and thread state.
 */
IDATA condvar_wait_impl(hycond_t *cond, osmutex_t *mutex, I_64 ms, IDATA nano, IDATA interruptable) {
    int r;
    int disable_count;
    hythread_t self;
    
    self = tm_self_tls;

    // check interrupted flag
    if (interruptable && self->interrupted) {
        // clean interrupted flag
        IDATA status = hythread_clear_interrupted_other(self);
        assert(status == TM_ERROR_INTERRUPT);
        return TM_ERROR_INTERRUPT;
    }

    // Store provided cond into current thread cond
    self->current_condition = interruptable ? cond : NULL;

    disable_count = hythread_reset_suspend_disable();

    r = os_cond_timedwait(cond, mutex, ms, nano);

    hythread_set_suspend_disable(disable_count);

    self->current_condition = NULL;
   
    // check interrupted flag
    if (interruptable &&  self->interrupted) {
        // clean interrupted flag
        IDATA status = hythread_clear_interrupted_other(self);
        assert(status == TM_ERROR_INTERRUPT);
        return TM_ERROR_INTERRUPT;
    }

    return r;
}
/**
 * Clear the interrupted flag of the current thread and return its previous value.
 * 
 * @return  previous value of interrupted flag: non-zero if the thread had been interrupted.
 * @see java.lang.Thread.interrupted()
 */
UDATA VMCALL hythread_clear_interrupted() {
    return hythread_clear_interrupted_other(tm_self_tls);
} // hythread_clear_interrupted
Exemplo n.º 3
0
/**
 * Clears the interruption flag for the specific <code>thread</code>.
 *
 * @param[in] java_thread where to clear interrupt flag
 * @sa java.lang.Thread.interrupted()
 */
IDATA VMCALL jthread_clear_interrupted(jthread java_thread)
{
    hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
    return hythread_clear_interrupted_other(tm_native_thread);
} // jthread_clear_interrupted