msg_error_t peer_wait_for_message(peer_t peer) { msg_error_t status; msg_comm_t comm = NULL; msg_task_t task = NULL; int idx = -1; int done = 0; while (!done) { comm = MSG_task_irecv(&task, peer->me); queue_pending_connection(comm, peer->pending_recvs); if ((idx = MSG_comm_waitany(peer->pending_recvs)) != -1) { comm = xbt_dynar_get_as(peer->pending_recvs, idx, msg_comm_t); status = MSG_comm_get_status(comm); XBT_DEBUG("peer_wait_for_message: error code = %d", status); xbt_assert(status == MSG_OK, "peer_wait_for_message() failed"); task = MSG_comm_get_task(comm); MSG_comm_destroy(comm); xbt_dynar_cursor_rm(peer->pending_recvs, (unsigned int*)&idx); done = peer_execute_task(peer, task); task_message_delete(task); task = NULL; } process_pending_connections(peer->pending_sends); } return status; }
int process_pending_connections(xbt_dynar_t q) { unsigned int iter; int status; int empty = 0; msg_comm_t comm; xbt_dynar_foreach(q, iter, comm) { empty = 1; if (MSG_comm_test(comm)) { MSG_comm_destroy(comm); status = MSG_comm_get_status(comm); xbt_assert(status == MSG_OK, "process_pending_connections() failed"); xbt_dynar_cursor_rm(q, &iter); empty = 0; } }
/* * This gets called the first time a category is referenced and performs the * initialization. * Also resets threshold to inherited! */ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority) { #define _xbt_log_cat_init(a, b) (0) if (log_cat_init_mutex != NULL) { xbt_os_rmutex_acquire(log_cat_init_mutex); } if (category->initialized) { if (log_cat_init_mutex != NULL) { xbt_os_rmutex_release(log_cat_init_mutex); } return priority >= category->threshold; } unsigned int cursor; xbt_log_setting_t setting = NULL; int found = 0; XBT_DEBUG("Initializing category '%s' (firstChild=%s, nextSibling=%s)", category->name, (category->firstChild ? category->firstChild->name : "none"), (category->nextSibling ? category->nextSibling->name : "none")); if (category == &_XBT_LOGV(XBT_LOG_ROOT_CAT)) { category->threshold = xbt_log_priority_info; category->appender = xbt_log_default_appender; category->layout = xbt_log_default_layout; } else { if (!category->parent) category->parent = &_XBT_LOGV(XBT_LOG_ROOT_CAT); XBT_DEBUG("Set %s (%s) as father of %s ", category->parent->name, (category->parent->initialized ? xbt_log_priority_names[category->parent->threshold] : "uninited"), category->name); xbt_log_parent_set(category, category->parent); if (XBT_LOG_ISENABLED(log, xbt_log_priority_debug)) { char *buf, *res = NULL; xbt_log_category_t cpp = category->parent->firstChild; while (cpp) { if (res) { buf = bprintf("%s %s", res, cpp->name); free(res); res = buf; } else { res = xbt_strdup(cpp->name); } cpp = cpp->nextSibling; } XBT_DEBUG("Children of %s: %s; nextSibling: %s", category->parent->name, res, (category->parent->nextSibling ? category->parent->nextSibling->name : "none")); free(res); } } /* Apply the control */ if (xbt_log_settings) { xbt_assert(category, "NULL category"); xbt_assert(category->name); xbt_dynar_foreach(xbt_log_settings, cursor, setting) { xbt_assert(setting, "Damnit, NULL cat in the list"); xbt_assert(setting->catname, "NULL setting(=%p)->catname", (void *) setting); if (!strcmp(setting->catname, category->name)) { found = 1; _xbt_log_cat_apply_set(category, setting); xbt_dynar_cursor_rm(xbt_log_settings, &cursor); } } if (!found) XBT_DEBUG("Category '%s': inherited threshold = %s (=%d)", category->name, xbt_log_priority_names[category->threshold], category->threshold); }