Пример #1
0
/**
 * Notify a single thread waiting on a monitor.
 *
 * A thread is considered to be waiting on the monitor if
 * it is currently blocked while executing hythread_monitor_wait on the monitor.
 *
 * If no threads are waiting, no action is taken.
 *
 * @param[in] mon_ptr a monitor to be signaled
 * @return  0 once the monitor has been signaled<br>HYTHREAD_ILLEGAL_MONITOR_STATE if the current thread does not own the monitor
 *
 * @see hythread_monitor_notify_all, hythread_monitor_enter, hythread_monitor_wait
 */
IDATA VMCALL hythread_monitor_notify(hythread_monitor_t mon_ptr) {
    if (mon_ptr->owner != tm_self_tls) {
        return TM_ERROR_ILLEGAL_STATE;
    }
    if (mon_ptr->notify_count < mon_ptr->wait_count)
        mon_ptr->notify_count++;
    return hycond_notify(&mon_ptr->condition);
}
Пример #2
0
/*
 * Exit locktable write section
 */
static void locktable_writer_exit() {
    IDATA status = port_mutex_lock(&lock_table->mutex);
    assert(status == TM_ERROR_NONE);

    if (lock_table->readers_reading > 0) {
        lock_table->readers_reading = lock_table->readers_waiting;
        lock_table->readers_waiting = 0;
        lock_table->state = HYTHREAD_LOCKTABLE_READING;
        hycond_notify_all(&lock_table->read);
    } else if (lock_table->writers_waiting > 0) {
        hycond_notify(&lock_table->write);
    } else {
        lock_table->state = HYTHREAD_LOCKTABLE_IDLE;
    }

    status = port_mutex_unlock(&lock_table->mutex);
    assert(status == TM_ERROR_NONE);
}