/** @brief Pop something from the message exchange queue. * * This is blocking if the queue is empty. * * @see #xbt_dynar_pop * */ void xbt_queue_pop(xbt_queue_t queue, void *const dst) { xbt_mutex_acquire(queue->mutex); while (xbt_dynar_is_empty(queue->data)) { XBT_DEBUG("Queue %p empty. Waiting", queue); xbt_cond_wait(queue->not_empty, queue->mutex); } xbt_dynar_pop(queue->data, dst); xbt_cond_signal(queue->not_full); xbt_mutex_release(queue->mutex); }
/** @brief Push something to the message exchange queue. * * This is blocking if the declared capacity is non-nul, and if this amount is reached. * * @see #xbt_dynar_push */ void xbt_queue_push(xbt_queue_t queue, const void *src) { xbt_mutex_acquire(queue->mutex); while (queue->capacity != 0 && queue->capacity == xbt_dynar_length(queue->data)) { XBT_DEBUG("Capacity of %p exceeded (=%d). Waiting", queue, queue->capacity); xbt_cond_wait(queue->not_full, queue->mutex); } xbt_dynar_push(queue->data, src); xbt_cond_signal(queue->not_empty); xbt_mutex_release(queue->mutex); }
/* This function move the emigrant on Jacquelin */ static int policeman(int argc, char *argv[]) { xbt_mutex_acquire(mutex); XBT_INFO("Wait a bit before migrating the emigrant."); while (process_to_migrate == NULL) xbt_cond_wait(cond, mutex); MSG_process_migrate(process_to_migrate, MSG_get_host_by_name("Jacquelin")); XBT_INFO("I moved the emigrant"); MSG_process_resume(process_to_migrate); xbt_mutex_release(mutex); return 0; } /* end_of_policeman */
void xbt_thread_join(xbt_thread_t thread) { xbt_mutex_acquire(thread->mutex); xbt_assert(thread->joinable, "Cannot join on %p: wasn't created joinable", thread); if (!thread->done) { xbt_cond_wait(thread->cond, thread->mutex); xbt_mutex_release(thread->mutex); } xbt_mutex_destroy(thread->mutex); xbt_cond_destroy(thread->cond); free(thread->name); free(thread); }