static int opal_event_base_open(mca_base_open_flag_t flags) { int rc = OPAL_SUCCESS; /* Silence compiler warning */ (void) flags; /* no need to open the components since we only use one */ /* init the lib */ if (OPAL_SUCCESS != (rc = opal_event_init())) { return rc; } /* Declare our intent to use threads */ opal_event_use_threads(); /* get our event base */ if (NULL == (opal_sync_event_base = opal_event_base_create())) { return OPAL_ERROR; } /* set the number of priorities */ if (0 < OPAL_EVENT_NUM_PRI) { opal_event_base_priority_init(opal_sync_event_base, OPAL_EVENT_NUM_PRI); } return rc; }
int main(int argc, char **argv) { char byte='a'; struct timespec tp= {0, 100}; int count=0; foo_caddy_t *foo; /* Initialize the event library */ opal_init(&argc, &argv); /* setup for threads */ opal_event_use_threads(); /* create a new base */ my_base = orte_event_base_create(); /* launch a progress thread on that base*/ pipe(progress_thread_pipe); OBJ_CONSTRUCT(&lock, opal_mutex_t); OBJ_CONSTRUCT(&cond, opal_condition_t); OBJ_CONSTRUCT(&progress_thread, opal_thread_t); progress_thread.t_run = progress_engine; if (OPAL_SUCCESS != opal_thread_start(&progress_thread)) { fprintf(stderr, "Unable to start progress thread\n"); orte_event_base_finalize(my_base); exit(1); } /* wait a little while - reflects reality in an async system */ while (count < 100) { nanosleep(&tp, NULL); count++; } count=0; /* make a dummy event */ fprintf(stderr, "activating the write_event"); foo = OBJ_NEW(foo_caddy_t); opal_event_set(my_base, &foo->write_event, -1, 0, send_handler, foo); /* activate it. */ opal_event_active(&foo->write_event, EV_WRITE, 1); /* wait for it to trigger */ while (!fd_written && count < 1000) { if (0 == (count % 100)) { fprintf(stderr, "Waiting...\n"); } nanosleep(&tp, NULL); count++; } /* stop the thread */ OPAL_ACQUIRE_THREAD(&lock, &cond, &active); progress_thread_stop = true; OPAL_RELEASE_THREAD(&lock, &cond, &active); opal_fd_write(progress_thread_pipe[1], 1, &byte); opal_thread_join(&progress_thread, NULL); /* release the base */ fprintf(stderr, "Cleaning up\n"); opal_finalize(); fprintf(stderr, "Cleanup completed\n"); return 0; }