2005-01-14 00:11:24 +00:00
|
|
|
#include "ompi_config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2005-03-14 20:57:21 +00:00
|
|
|
#ifdef HAVE_SYS_FCNTL_H
|
|
|
|
#include <sys/fcntl.h>
|
2005-01-14 00:11:24 +00:00
|
|
|
#endif
|
2005-04-11 03:43:35 +00:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2005-01-14 00:11:24 +00:00
|
|
|
#include <netinet/in.h>
|
2005-04-11 03:43:35 +00:00
|
|
|
#endif
|
2005-01-14 00:11:24 +00:00
|
|
|
#include "util/output.h"
|
|
|
|
#include "mca/oob/base/base.h"
|
|
|
|
#include "mca/iof/base/base.h"
|
2005-04-11 03:43:35 +00:00
|
|
|
#include "mca/iof/base/iof_base_endpoint.h"
|
|
|
|
#include "mca/iof/base/iof_base_fragment.h"
|
2005-01-14 00:11:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* timer callback out of the event loop
|
|
|
|
*/
|
|
|
|
|
2005-03-14 20:57:21 +00:00
|
|
|
static void orte_iof_base_timer_cb(int fd, short flags, void *cbdata)
|
2005-01-14 00:11:24 +00:00
|
|
|
{
|
|
|
|
int *flushed = (int*)cbdata;
|
2005-03-14 20:57:21 +00:00
|
|
|
OMPI_THREAD_LOCK(&orte_iof_base.iof_lock);
|
2005-01-14 00:11:24 +00:00
|
|
|
*flushed = 1;
|
2005-03-14 20:57:21 +00:00
|
|
|
ompi_condition_signal(&orte_iof_base.iof_condition);
|
|
|
|
OMPI_THREAD_UNLOCK(&orte_iof_base.iof_lock);
|
2005-01-14 00:11:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flush output streams and block until there is no pending I/O
|
|
|
|
* on any of the current endpoints.
|
|
|
|
*/
|
|
|
|
|
2005-03-14 20:57:21 +00:00
|
|
|
int orte_iof_base_flush(void)
|
2005-01-14 00:11:24 +00:00
|
|
|
{
|
|
|
|
ompi_list_item_t* item;
|
|
|
|
ompi_event_t ev;
|
|
|
|
struct timeval tv = { 0, 0 };
|
|
|
|
int flushed = 0;
|
|
|
|
size_t pending;
|
|
|
|
|
|
|
|
/* flush any pending output */
|
|
|
|
fflush(NULL);
|
2005-04-20 15:43:00 +00:00
|
|
|
|
2005-01-14 00:11:24 +00:00
|
|
|
/* force all file descriptors to be progressed at least once,
|
|
|
|
* wait on a timer callback to be called out of the event loop
|
|
|
|
*/
|
|
|
|
|
2005-04-20 15:43:00 +00:00
|
|
|
if(ompi_event_progress_thread() == false) {
|
|
|
|
OMPI_THREAD_LOCK(&orte_iof_base.iof_lock);
|
|
|
|
ompi_evtimer_set(&ev, orte_iof_base_timer_cb, &flushed);
|
|
|
|
ompi_event_add(&ev, &tv);
|
|
|
|
while(flushed == 0)
|
|
|
|
ompi_condition_wait(&orte_iof_base.iof_condition, &orte_iof_base.iof_lock);
|
|
|
|
} else {
|
|
|
|
ompi_event_loop(OMPI_EVLOOP_NONBLOCK);
|
|
|
|
OMPI_THREAD_LOCK(&orte_iof_base.iof_lock);
|
|
|
|
}
|
2005-03-14 20:57:21 +00:00
|
|
|
orte_iof_base.iof_waiting++;
|
|
|
|
|
2005-01-14 00:11:24 +00:00
|
|
|
/* wait for all of the endpoints to reach an idle state */
|
2005-03-14 20:57:21 +00:00
|
|
|
pending = ompi_list_get_size(&orte_iof_base.iof_endpoints);
|
|
|
|
while(pending > 0) {
|
2005-01-14 00:11:24 +00:00
|
|
|
pending = 0;
|
2005-03-14 20:57:21 +00:00
|
|
|
for(item = ompi_list_get_first(&orte_iof_base.iof_endpoints);
|
|
|
|
item != ompi_list_get_end(&orte_iof_base.iof_endpoints);
|
2005-01-14 00:11:24 +00:00
|
|
|
item = ompi_list_get_next(item)) {
|
2005-03-14 20:57:21 +00:00
|
|
|
orte_iof_base_endpoint_t* endpoint = (orte_iof_base_endpoint_t*)item;
|
2005-06-01 19:23:23 +00:00
|
|
|
/* BWB - XXX - FIXME - need to remove the ep_mode test -
|
|
|
|
Tim looking at it */
|
|
|
|
if(endpoint->ep_mode == ORTE_IOF_SINK && orte_iof_base_endpoint_pending(endpoint)) {
|
2005-01-14 00:11:24 +00:00
|
|
|
pending++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(pending != 0) {
|
2005-04-20 15:43:00 +00:00
|
|
|
if(ompi_event_progress_thread() == false) {
|
|
|
|
ompi_condition_wait(&orte_iof_base.iof_condition, &orte_iof_base.iof_lock);
|
|
|
|
} else {
|
|
|
|
OMPI_THREAD_UNLOCK(&orte_iof_base.iof_lock);
|
|
|
|
ompi_event_loop(OMPI_EVLOOP_ONCE);
|
|
|
|
OMPI_THREAD_LOCK(&orte_iof_base.iof_lock);
|
|
|
|
}
|
2005-01-14 00:11:24 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-14 20:57:21 +00:00
|
|
|
orte_iof_base.iof_waiting--;
|
|
|
|
OMPI_THREAD_UNLOCK(&orte_iof_base.iof_lock);
|
2005-01-14 00:11:24 +00:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|