/*---------------------------------------------------------------------------*/ na_context_t * NA_Context_create(na_class_t *na_class) { na_return_t ret = NA_SUCCESS; struct na_private_context *na_private_context = NULL; if (!na_class) { NA_LOG_ERROR("NULL NA class"); ret = NA_INVALID_PARAM; goto done; } na_private_context = (struct na_private_context *) malloc( sizeof(struct na_private_context)); if (!na_private_context) { NA_LOG_ERROR("Could not allocate context"); ret = NA_NOMEM_ERROR; goto done; } if (na_class->context_create) { ret = na_class->context_create(na_class, &na_private_context->context.plugin_context); if (ret != NA_SUCCESS) { goto done; } } /* Initialize completion queue */ na_private_context->completion_queue = hg_queue_new(); if (!na_private_context->completion_queue) { NA_LOG_ERROR("Could not create completion queue"); ret = NA_NOMEM_ERROR; goto done; } /* Initialize completion queue mutex/cond */ hg_thread_mutex_init(&na_private_context->completion_queue_mutex); hg_thread_cond_init(&na_private_context->completion_queue_cond); /* Initialize progress mutex/cond */ hg_thread_mutex_init(&na_private_context->progress_mutex); hg_thread_cond_init(&na_private_context->progress_cond); na_private_context->progressing = NA_FALSE; done: if (ret != NA_SUCCESS) { free(na_private_context); na_private_context = NULL; } return (na_context_t *) na_private_context; }
int main(int argc, char *argv[]) { hg_thread_t thread[MERCURY_TESTING_NUM_THREADS]; int ret = EXIT_SUCCESS; int i; (void) argc; (void) argv; for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++) hg_thread_init(&thread[i]); hg_thread_mutex_init(&thread_mutex); hg_thread_cond_init(&thread_cond); for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++) hg_thread_create(&thread[i], thread_cb_cond, NULL); for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++) hg_thread_join(thread[i]); working = 1; for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++) hg_thread_create(&thread[i], thread_cb_cond_all, NULL); hg_thread_mutex_lock(&thread_mutex); working = 0; hg_thread_cond_broadcast(&thread_cond); hg_thread_mutex_unlock(&thread_mutex); for (i = 0; i < MERCURY_TESTING_NUM_THREADS; i++) hg_thread_join(thread[i]); return ret; }