2006-07-27 05:51:18 +04:00
|
|
|
/*
|
2008-03-23 15:33:04 +03:00
|
|
|
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
|
2009-02-16 23:03:48 +03:00
|
|
|
* Copyright (c) 2008-2009 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2006-07-27 05:51:18 +04:00
|
|
|
* Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include "opal_config.h"
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2008-03-23 15:33:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
#include "misc.h"
|
|
|
|
#endif
|
2006-07-27 05:51:18 +04:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
2008-03-28 20:30:33 +03:00
|
|
|
#else
|
|
|
|
# ifndef HAVE_WINSOCK2_H
|
2006-07-27 05:51:18 +04:00
|
|
|
#include <sys/_time.h>
|
2008-03-28 20:30:33 +03:00
|
|
|
# endif
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
#ifndef HAVE_TIMERADD
|
|
|
|
#include <sys/_timeradd.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-03-23 15:33:04 +03:00
|
|
|
#ifndef WIN32
|
2006-07-27 05:51:18 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2008-03-23 15:33:04 +03:00
|
|
|
#endif
|
2006-07-27 05:51:18 +04:00
|
|
|
#include <errno.h>
|
2008-03-23 15:33:04 +03:00
|
|
|
#include <signal.h>
|
2006-07-27 05:51:18 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2008-03-23 15:33:04 +03:00
|
|
|
#include <time.h>
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
#include "opal/event/event.h"
|
|
|
|
#include "opal/class/opal_object.h"
|
|
|
|
#include "opal/threads/mutex.h"
|
|
|
|
#include "opal/threads/threads.h"
|
|
|
|
#include "opal/util/output.h"
|
|
|
|
#include "opal/constants.h"
|
2008-03-23 15:33:04 +03:00
|
|
|
#include "opal/util/argv.h"
|
|
|
|
#include "opal/mca/base/mca_base_param.h"
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
#include "event-internal.h"
|
2008-03-23 15:33:04 +03:00
|
|
|
#include "evutil.h"
|
2006-07-27 05:51:18 +04:00
|
|
|
#include "log.h"
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
#if defined(HAVE_EVENT_PORTS) && HAVE_EVENT_PORTS
|
|
|
|
extern const struct eventop evportops;
|
|
|
|
#endif
|
2006-07-27 05:51:18 +04:00
|
|
|
#if defined(HAVE_SELECT) && HAVE_SELECT
|
2008-03-23 15:33:04 +03:00
|
|
|
extern const struct eventop selectops;
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_POLL) && HAVE_POLL && HAVE_WORKING_POLL
|
2008-03-23 15:33:04 +03:00
|
|
|
extern const struct eventop pollops;
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_EPOLL) && HAVE_EPOLL
|
2008-03-23 15:33:04 +03:00
|
|
|
extern const struct eventop epollops;
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_WORKING_KQUEUE) && HAVE_WORKING_KQUEUE
|
2008-03-23 15:33:04 +03:00
|
|
|
extern const struct eventop kqops;
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_DEVPOLL
|
2008-03-23 15:33:04 +03:00
|
|
|
extern const struct eventop devpollops;
|
|
|
|
#endif
|
|
|
|
#ifdef WIN32
|
|
|
|
extern const struct eventop win32ops;
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* In order of preference */
|
2008-03-23 15:33:04 +03:00
|
|
|
const struct eventop *eventops[] = {
|
|
|
|
#if defined(HAVE_EVENT_PORTS) && HAVE_EVENT_PORTS
|
|
|
|
&evportops,
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
2008-03-23 15:33:04 +03:00
|
|
|
#if defined(HAVE_WORKING_KQUEUE) && HAVE_WORKING_KQUEUE
|
|
|
|
&kqops,
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
2008-03-23 15:33:04 +03:00
|
|
|
#if defined(HAVE_EPOLL) && HAVE_EPOLL
|
|
|
|
&epollops,
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
2008-03-23 15:33:04 +03:00
|
|
|
#if defined(HAVE_DEVPOLL) && HAVE_DEVPOLL
|
2006-07-27 05:51:18 +04:00
|
|
|
&devpollops,
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_POLL) && HAVE_POLL && HAVE_WORKING_POLL
|
2008-03-23 15:33:04 +03:00
|
|
|
&pollops,
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_SELECT) && HAVE_SELECT
|
2008-03-23 15:33:04 +03:00
|
|
|
&selectops,
|
|
|
|
#endif
|
|
|
|
#ifdef WIN32
|
|
|
|
&win32ops,
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Global state */
|
|
|
|
struct event_base *current_base = NULL;
|
2008-03-23 15:33:04 +03:00
|
|
|
extern struct event_base *evsignal_base;
|
|
|
|
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
|
|
|
|
static int use_monotonic;
|
|
|
|
#endif /* defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) */
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
/* Handle signals - This is a deprecated interface */
|
2008-03-23 15:33:04 +03:00
|
|
|
int (*event_sigcb)(void); /* Signal callback when gotsig is set */
|
|
|
|
volatile sig_atomic_t event_gotsig; /* Set in signal handler */
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
/* Prototypes */
|
2008-03-23 15:33:04 +03:00
|
|
|
static void event_queue_insert(struct event_base *, struct event *, int);
|
|
|
|
static void event_queue_remove(struct event_base *, struct event *, int);
|
|
|
|
static int event_haveevents(struct event_base *);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
static void event_process_active(struct event_base *);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
static int timeout_next(struct event_base *, struct timeval **);
|
2006-07-27 05:51:18 +04:00
|
|
|
static void timeout_process(struct event_base *);
|
2008-03-23 15:33:04 +03:00
|
|
|
#if 0
|
|
|
|
/* Let's not delete this yet */
|
2006-07-27 05:51:18 +04:00
|
|
|
static void timeout_correct(struct event_base *, struct timeval *);
|
2008-03-23 15:33:04 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
detect_monotonic(void)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
|
|
|
|
use_monotonic = 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gettime(struct timeval *tp)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (use_monotonic) {
|
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
tp->tv_sec = ts.tv_sec;
|
|
|
|
tp->tv_usec = ts.tv_nsec / 1000;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (gettimeofday(tp, NULL));
|
|
|
|
}
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC opal_mutex_t opal_event_lock;
|
2006-07-27 05:51:18 +04:00
|
|
|
static int opal_event_inited = 0;
|
|
|
|
static bool opal_event_enabled = false;
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
static opal_thread_t opal_event_thread;
|
|
|
|
static opal_event_t opal_event_pipe_event;
|
|
|
|
static int opal_event_pipe[2];
|
|
|
|
static int opal_event_pipe_signalled;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool opal_event_progress_thread(void)
|
|
|
|
{
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
return opal_using_threads() ? opal_thread_self_compare(&opal_event_thread) : true;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
/* run loop for dispatch thread */
|
|
|
|
static void* opal_event_run(opal_object_t* arg)
|
|
|
|
{
|
|
|
|
/* Open MPI: Prevent compiler warnings about unused variables */
|
|
|
|
#if defined(NDEBUG)
|
2008-03-23 15:33:04 +03:00
|
|
|
event_loop(0);
|
2006-07-27 05:51:18 +04:00
|
|
|
#else
|
2008-03-23 15:33:04 +03:00
|
|
|
int rc = event_loop(0);
|
2006-07-27 05:51:18 +04:00
|
|
|
assert(rc >= 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
opal_mutex_lock(&opal_event_lock);
|
2008-03-23 15:33:04 +03:00
|
|
|
event_del(&opal_event_pipe_event);
|
2006-07-27 05:51:18 +04:00
|
|
|
close(opal_event_pipe[0]);
|
|
|
|
close(opal_event_pipe[1]);
|
|
|
|
opal_event_pipe[0] = -1;
|
|
|
|
opal_event_pipe[1] = -1;
|
|
|
|
opal_mutex_unlock(&opal_event_lock);
|
2007-01-14 15:28:36 +03:00
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-01-14 15:28:36 +03:00
|
|
|
#endif /* OMPI_ENABLE_PROGRESS_THREADS */
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
static void opal_event_pipe_handler(int sd, short flags, void* user)
|
|
|
|
{
|
|
|
|
unsigned char byte;
|
|
|
|
if(read(sd, &byte, 1) < 0) {
|
|
|
|
opal_output(0, "opal_event_pipe: read failed with: errno=%d\n", errno);
|
|
|
|
opal_event_del(&opal_event_pipe_event);
|
|
|
|
}
|
|
|
|
}
|
2007-01-14 15:28:36 +03:00
|
|
|
#endif /* OMPI_ENABLE_PROGRESS_THREADS */
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
static char** opal_event_module_include = NULL;
|
|
|
|
|
|
|
|
static int opal_event_allow_system( const char* eventop_name)
|
|
|
|
{
|
|
|
|
char** argv = opal_event_module_include;
|
|
|
|
|
|
|
|
/* if the user specified an event interface - use these exclusively */
|
|
|
|
while(argv && *argv) {
|
|
|
|
if( 0 == strcmp(*argv, "all") ) return 1; /* all match */
|
|
|
|
if( 0 == strcmp(*argv, eventop_name) ) return 1;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
int
|
|
|
|
opal_event_init(void)
|
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event_base *base;
|
|
|
|
char* event_module_include;
|
|
|
|
|
|
|
|
if(opal_event_inited++ != 0)
|
|
|
|
return OPAL_SUCCESS;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
#if OPAL_HAVE_WORKING_EVENTOPS
|
|
|
|
|
2008-03-25 20:18:17 +03:00
|
|
|
/* Retrieve the upper level specified event system, if any.
|
|
|
|
* Default to select() on OS X and poll() everywhere else because
|
|
|
|
* various parts of OMPI / ORTE use libevent with pty's. pty's
|
|
|
|
* *only* work with select on OS X (tested on Tiger and Leopard);
|
|
|
|
* we *know* that both select and poll works with pty's everywhere
|
|
|
|
* else we care about (other mechansisms such as epoll *may* work
|
|
|
|
* with pty's -- we have not tested comprehensively with newer
|
|
|
|
* versions of Linux, etc.). So the safe thing to do is:
|
|
|
|
*
|
|
|
|
* - On OS X, default to using "select" only
|
|
|
|
* - Everywhere else, default to using "poll" only (because poll
|
|
|
|
* is more scalable than select)
|
|
|
|
*
|
|
|
|
* An upper layer may override this setting if it knows that pty's
|
|
|
|
* won't be used with libevent. For example, we currently have
|
|
|
|
* ompi_mpi_init() set to use "all" (to include epoll and friends)
|
|
|
|
* so that the TCP BTL can be a bit more scalable -- because we
|
|
|
|
* *know* that MPI apps don't use pty's with libevent.
|
|
|
|
* Note that other tools explicitly *do* use pty's with libevent:
|
|
|
|
*
|
|
|
|
* - orted
|
|
|
|
* - orterun (probably only if it launches locally)
|
|
|
|
* - ...?
|
2008-03-23 15:33:04 +03:00
|
|
|
*/
|
2008-04-17 22:16:54 +04:00
|
|
|
{
|
|
|
|
const struct eventop** _eventop = eventops;
|
|
|
|
char available_eventops[1024] = "none";
|
|
|
|
char* help_msg = NULL;
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
while( NULL != (*_eventop) ) {
|
|
|
|
if( 0 != position ) {
|
|
|
|
position += snprintf( available_eventops + position,
|
|
|
|
(size_t)(1024 - position),
|
|
|
|
", %s", (*_eventop)->name );
|
|
|
|
} else {
|
|
|
|
position += snprintf( available_eventops + position,
|
|
|
|
(size_t)(1024 - position),
|
|
|
|
"%s", (*_eventop)->name );
|
|
|
|
}
|
|
|
|
available_eventops[position] = '\0';
|
|
|
|
_eventop++; /* go to the next available eventop */
|
|
|
|
}
|
|
|
|
asprintf( &help_msg,
|
|
|
|
"Comma-delimited list of libevent subsystems "
|
|
|
|
"to use (%s -- available on your platform)",
|
|
|
|
available_eventops );
|
|
|
|
mca_base_param_reg_string_name("opal", "event_include",
|
|
|
|
help_msg, false, false,
|
2008-03-25 20:18:17 +03:00
|
|
|
#ifdef __APPLE__
|
2008-04-17 22:16:54 +04:00
|
|
|
"select",
|
2008-03-25 20:18:17 +03:00
|
|
|
#else
|
2008-12-11 00:13:10 +03:00
|
|
|
# ifdef __WINDOWS__
|
|
|
|
"win32",
|
|
|
|
# else
|
2008-04-17 22:16:54 +04:00
|
|
|
"poll",
|
2008-12-11 00:13:10 +03:00
|
|
|
# endif
|
2008-03-25 20:18:17 +03:00
|
|
|
#endif
|
2008-04-17 22:16:54 +04:00
|
|
|
&event_module_include);
|
|
|
|
free(help_msg); /* release the help message */
|
|
|
|
}
|
2008-03-23 15:33:04 +03:00
|
|
|
if (NULL == event_module_include) {
|
|
|
|
/* Shouldn't happen, but... */
|
2008-03-25 20:18:17 +03:00
|
|
|
event_module_include = strdup("select");
|
2008-03-23 15:33:04 +03:00
|
|
|
}
|
|
|
|
opal_event_module_include = opal_argv_split(event_module_include,',');
|
|
|
|
free(event_module_include);
|
|
|
|
|
|
|
|
base = event_base_new();
|
|
|
|
OBJ_CONSTRUCT(&opal_event_lock, opal_mutex_t);
|
|
|
|
if (base != NULL)
|
|
|
|
opal_current_base = base;
|
|
|
|
opal_event_enable();
|
|
|
|
#endif
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event_base *
|
|
|
|
event_base_new(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct event_base *base;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if ((base = calloc(1, sizeof(struct event_base))) == NULL)
|
|
|
|
event_err(1, "%s: calloc", __func__);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
event_sigcb = NULL;
|
|
|
|
event_gotsig = 0;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
detect_monotonic();
|
|
|
|
gettime(&base->event_tv);
|
|
|
|
|
|
|
|
min_heap_ctor(&base->timeheap);
|
|
|
|
TAILQ_INIT(&base->eventqueue);
|
|
|
|
TAILQ_INIT(&base->sig.signalqueue);
|
|
|
|
base->sig.ev_signal_pair[0] = -1;
|
|
|
|
base->sig.ev_signal_pair[1] = -1;
|
|
|
|
|
|
|
|
base->evbase = NULL;
|
|
|
|
for (i = 0; eventops[i] && !base->evbase; i++) {
|
|
|
|
/* Allow only the user selected event mechanisms to be initialized */
|
|
|
|
if( !opal_event_allow_system(eventops[i]->name) ) continue;
|
|
|
|
base->evsel = eventops[i];
|
|
|
|
|
|
|
|
base->evbase = base->evsel->init(base);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (base->evbase == NULL)
|
2006-07-27 05:51:18 +04:00
|
|
|
event_errx(1, "%s: no event mechanism available", __func__);
|
|
|
|
|
|
|
|
if (getenv("EVENT_SHOW_METHOD"))
|
|
|
|
event_msgx("libevent using: %s\n",
|
2008-03-23 15:33:04 +03:00
|
|
|
base->evsel->name);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
/* allocate a single active event queue */
|
2008-03-23 15:33:04 +03:00
|
|
|
event_base_priority_init(base, 1);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
return (base);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int opal_event_fini(void)
|
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
opal_event_disable();
|
|
|
|
opal_event_inited--;
|
|
|
|
if (NULL != opal_event_module_include) {
|
|
|
|
opal_argv_free(opal_event_module_include);
|
|
|
|
}
|
2009-02-16 23:03:48 +03:00
|
|
|
if( NULL != opal_current_base ) {
|
|
|
|
event_base_free(opal_current_base);
|
|
|
|
opal_current_base = NULL;
|
|
|
|
}
|
2009-02-16 22:18:43 +03:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
return OPAL_SUCCESS;
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int opal_event_enable(void)
|
|
|
|
{
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
if(opal_using_threads()) {
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
opal_mutex_lock(&opal_event_lock);
|
|
|
|
if(opal_event_inited > 0 && opal_event_enabled == true) {
|
|
|
|
opal_mutex_unlock(&opal_event_lock);
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a pipe to signal the event thread */
|
|
|
|
if(pipe(opal_event_pipe) != 0) {
|
|
|
|
opal_output(0, "opal_event_init: pipe() failed with errno=%d\n", errno);
|
|
|
|
opal_mutex_unlock(&opal_event_lock);
|
|
|
|
return OPAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
opal_event_pipe_signalled = 1;
|
2008-03-23 15:33:04 +03:00
|
|
|
event_set(
|
2006-07-27 05:51:18 +04:00
|
|
|
&opal_event_pipe_event,
|
|
|
|
opal_event_pipe[0],
|
2008-03-23 15:33:04 +03:00
|
|
|
EV_READ|EV_PERSIST,
|
2006-07-27 05:51:18 +04:00
|
|
|
opal_event_pipe_handler,
|
|
|
|
0);
|
2008-03-23 15:33:04 +03:00
|
|
|
event_add(&opal_event_pipe_event, 0);
|
2006-07-27 05:51:18 +04:00
|
|
|
opal_event_pipe_signalled = 0;
|
|
|
|
|
|
|
|
/* spin up a thread to dispatch events */
|
|
|
|
OBJ_CONSTRUCT(&opal_event_thread, opal_thread_t);
|
|
|
|
opal_event_enabled = true;
|
|
|
|
opal_event_thread.t_run = opal_event_run;
|
|
|
|
if((rc = opal_thread_start(&opal_event_thread)) != OPAL_SUCCESS) {
|
|
|
|
opal_mutex_unlock(&opal_event_lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
opal_mutex_unlock(&opal_event_lock);
|
|
|
|
} else {
|
|
|
|
opal_event_pipe[0] = -1;
|
|
|
|
opal_event_pipe[1] = -1;
|
|
|
|
opal_event_enabled = true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
opal_event_enabled = true;
|
|
|
|
#endif
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int opal_event_disable(void)
|
|
|
|
{
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
if(opal_using_threads()) {
|
|
|
|
opal_mutex_lock(&opal_event_lock);
|
|
|
|
if(opal_event_inited > 0 && opal_event_enabled == false) {
|
|
|
|
opal_mutex_unlock(&opal_event_lock);
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
opal_event_enabled = false;
|
|
|
|
if(opal_event_pipe_signalled == 0) {
|
|
|
|
unsigned char byte = 0;
|
|
|
|
if(write(opal_event_pipe[1], &byte, 1) != 1)
|
|
|
|
opal_output(0, "opal_event_add: write() to opal_event_pipe[1] failed with errno=%d\n", errno);
|
|
|
|
opal_event_pipe_signalled++;
|
|
|
|
}
|
|
|
|
opal_mutex_unlock(&opal_event_lock);
|
|
|
|
opal_thread_join(&opal_event_thread, NULL);
|
|
|
|
} else {
|
|
|
|
opal_event_enabled = false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
opal_event_enabled = false;
|
|
|
|
#endif
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int opal_event_restart(void)
|
|
|
|
{
|
2006-08-23 04:29:35 +04:00
|
|
|
#if OPAL_HAVE_WORKING_EVENTOPS && !defined(__WINDOWS__)
|
2006-07-27 05:51:18 +04:00
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
opal_mutex_lock(&opal_event_lock);
|
|
|
|
if(opal_event_pipe[0] >= 0) {
|
2008-03-23 15:33:04 +03:00
|
|
|
event_del(&opal_event_pipe_event);
|
2006-07-27 05:51:18 +04:00
|
|
|
/* do not close pipes - in case of bproc_vrfork they are not open
|
|
|
|
* and we may close something else
|
|
|
|
*/
|
|
|
|
opal_event_pipe[0] = -1;
|
|
|
|
opal_event_pipe[1] = -1;
|
|
|
|
}
|
|
|
|
opal_event_enabled = false;
|
|
|
|
opal_mutex_unlock(&opal_event_lock);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
opal_event_enable();
|
|
|
|
return (OPAL_SUCCESS);
|
|
|
|
#else /* OPAL_HAVE_WORKING_EVENTOPS */
|
|
|
|
return OPAL_ERR_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
void
|
|
|
|
event_base_free(struct event_base *base)
|
|
|
|
{
|
|
|
|
int i, n_deleted=0;
|
|
|
|
struct event *ev;
|
|
|
|
|
|
|
|
if (base == NULL && current_base)
|
|
|
|
base = current_base;
|
|
|
|
if (base == current_base)
|
|
|
|
current_base = NULL;
|
|
|
|
|
|
|
|
/* XXX(niels) - check for internal events first */
|
|
|
|
assert(base);
|
|
|
|
/* Delete all non-internal events. */
|
|
|
|
for (ev = TAILQ_FIRST(&base->eventqueue); ev; ) {
|
|
|
|
struct event *next = TAILQ_NEXT(ev, ev_next);
|
|
|
|
if (!(ev->ev_flags & EVLIST_INTERNAL)) {
|
|
|
|
opal_event_del(ev);
|
|
|
|
++n_deleted;
|
|
|
|
}
|
|
|
|
ev = next;
|
|
|
|
}
|
|
|
|
while ((ev = min_heap_top(&base->timeheap)) != NULL) {
|
|
|
|
opal_event_del(ev);
|
|
|
|
++n_deleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_deleted)
|
|
|
|
event_debug(("%s: %d events were still set in base",
|
|
|
|
__func__, n_deleted));
|
|
|
|
|
|
|
|
if (base->evsel->dealloc != NULL)
|
|
|
|
base->evsel->dealloc(base, base->evbase);
|
|
|
|
|
|
|
|
for (i = 0; i < base->nactivequeues; ++i)
|
|
|
|
assert(TAILQ_EMPTY(base->activequeues[i]));
|
|
|
|
|
|
|
|
assert(min_heap_empty(&base->timeheap));
|
|
|
|
min_heap_dtor(&base->timeheap);
|
|
|
|
|
|
|
|
for (i = 0; i < base->nactivequeues; ++i)
|
|
|
|
free(base->activequeues[i]);
|
|
|
|
free(base->activequeues);
|
|
|
|
|
|
|
|
assert(TAILQ_EMPTY(&base->eventqueue));
|
|
|
|
|
|
|
|
free(base);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reinitialized the event base after a fork */
|
2006-07-27 05:51:18 +04:00
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_reinit(struct event_base *base)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
const struct eventop *evsel = base->evsel;
|
|
|
|
void *evbase = base->evbase;
|
|
|
|
int res = 0;
|
|
|
|
struct event *ev;
|
|
|
|
|
|
|
|
/* check if this event mechanism requires reinit */
|
|
|
|
if (!evsel->need_reinit)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (base->evsel->dealloc != NULL)
|
|
|
|
base->evsel->dealloc(base, base->evbase);
|
|
|
|
base->evbase = evsel->init(base);
|
|
|
|
if (base->evbase == NULL)
|
|
|
|
event_errx(1, "%s: could not reinitialize event mechanism",
|
|
|
|
__func__);
|
|
|
|
|
|
|
|
TAILQ_FOREACH(ev, &base->eventqueue, ev_next) {
|
|
|
|
if (evsel->add(evbase, ev) == -1)
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (res);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_priority_init(int npriorities)
|
|
|
|
{
|
|
|
|
return event_base_priority_init(current_base, npriorities);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
event_base_priority_init(struct event_base *base, int npriorities)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (base->event_count_active)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (base->nactivequeues && npriorities != base->nactivequeues) {
|
|
|
|
for (i = 0; i < base->nactivequeues; ++i) {
|
|
|
|
free(base->activequeues[i]);
|
|
|
|
}
|
|
|
|
free(base->activequeues);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate our priority queues */
|
|
|
|
base->nactivequeues = npriorities;
|
2008-03-23 15:33:04 +03:00
|
|
|
base->activequeues = (struct event_list **)calloc(base->nactivequeues,
|
|
|
|
npriorities * sizeof(struct event_list *));
|
2006-07-27 05:51:18 +04:00
|
|
|
if (base->activequeues == NULL)
|
|
|
|
event_err(1, "%s: calloc", __func__);
|
|
|
|
|
|
|
|
for (i = 0; i < base->nactivequeues; ++i) {
|
2008-03-23 15:33:04 +03:00
|
|
|
base->activequeues[i] = malloc(sizeof(struct event_list));
|
2006-07-27 05:51:18 +04:00
|
|
|
if (base->activequeues[i] == NULL)
|
|
|
|
event_err(1, "%s: malloc", __func__);
|
|
|
|
TAILQ_INIT(base->activequeues[i]);
|
|
|
|
}
|
2008-03-23 15:33:04 +03:00
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_haveevents(struct event_base *base)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
return (base->event_count > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Active events are stored in priority queues. Lower priorities are always
|
|
|
|
* process before higher priorities. Low priority events can starve high
|
|
|
|
* priority ones.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2008-03-23 15:33:04 +03:00
|
|
|
event_process_active(struct event_base *base)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event *ev;
|
|
|
|
struct event_list *activeq = NULL;
|
2006-07-27 05:51:18 +04:00
|
|
|
int i;
|
|
|
|
short ncalls;
|
|
|
|
|
|
|
|
for (i = 0; i < base->nactivequeues; ++i) {
|
|
|
|
if (TAILQ_FIRST(base->activequeues[i]) != NULL) {
|
|
|
|
activeq = base->activequeues[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
assert(activeq != NULL);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
for (ev = TAILQ_FIRST(activeq); ev; ev = TAILQ_FIRST(activeq)) {
|
|
|
|
if (ev->ev_events & EV_PERSIST)
|
|
|
|
event_queue_remove(base, ev, EVLIST_ACTIVE);
|
|
|
|
else
|
|
|
|
event_del(ev);
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
/* Allows deletes to work */
|
|
|
|
ncalls = ev->ev_ncalls;
|
|
|
|
ev->ev_pncalls = &ncalls;
|
|
|
|
while (ncalls) {
|
|
|
|
ncalls--;
|
|
|
|
ev->ev_ncalls = ncalls;
|
2006-08-24 02:19:31 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&opal_event_lock);
|
2008-03-23 15:33:04 +03:00
|
|
|
(*ev->ev_callback)((int)ev->ev_fd, ev->ev_res, ev->ev_arg);
|
|
|
|
OPAL_THREAD_LOCK(&opal_event_lock);
|
|
|
|
if (event_gotsig || base->event_break)
|
|
|
|
return;
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait continously for events. We exit only if no events are left.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_dispatch(void)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
return (event_loop(0));
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_base_dispatch(struct event_base *event_base)
|
|
|
|
{
|
|
|
|
return (event_base_loop(event_base, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
event_base_get_method(struct event_base *base)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
assert(base);
|
|
|
|
return (base->evsel->name);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
event_loopexit_cb(int fd, short what, void *arg)
|
|
|
|
{
|
2007-08-07 21:09:54 +04:00
|
|
|
#if OPAL_HAVE_WORKING_EVENTOPS
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event_base *base = arg;
|
2006-07-27 05:51:18 +04:00
|
|
|
base->event_gotterm = 1;
|
2007-08-07 21:09:54 +04:00
|
|
|
#endif /* OPAL_HAVE_WORKING_EVENTOPS */
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* not thread safe */
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_loopexit(struct timeval *tv)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
return (event_once(-1, EV_TIMEOUT, event_loopexit_cb,
|
|
|
|
current_base, tv));
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
event_base_loopexit(struct event_base *event_base, struct timeval *tv)
|
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
return (event_base_once(event_base, -1, EV_TIMEOUT, event_loopexit_cb,
|
2006-07-27 05:51:18 +04:00
|
|
|
event_base, tv));
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
/* not thread safe */
|
|
|
|
int
|
|
|
|
event_loopbreak(void)
|
|
|
|
{
|
|
|
|
return (event_base_loopbreak(current_base));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
event_base_loopbreak(struct event_base *event_base)
|
|
|
|
{
|
|
|
|
if (event_base == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
event_base->event_break = 1;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
/* not thread safe */
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_loop(int flags)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
return event_base_loop(current_base, flags);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_base_loop(struct event_base *base, int flags)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2007-08-07 21:09:54 +04:00
|
|
|
#if OPAL_HAVE_WORKING_EVENTOPS
|
2008-03-23 15:33:04 +03:00
|
|
|
const struct eventop *evsel = base->evsel;
|
2006-07-27 05:51:18 +04:00
|
|
|
void *evbase = base->evbase;
|
|
|
|
struct timeval tv;
|
2008-03-23 15:33:04 +03:00
|
|
|
struct timeval *tv_p;
|
2006-07-27 05:51:18 +04:00
|
|
|
int res, done;
|
2006-08-23 00:07:42 +04:00
|
|
|
#endif /* OPAL_HAVE_WORKING_EVENTOPS */
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (opal_event_inited == false)
|
2006-07-27 05:51:18 +04:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
#if OPAL_HAVE_WORKING_EVENTOPS
|
2007-07-24 23:10:19 +04:00
|
|
|
res = OPAL_THREAD_TRYLOCK(&opal_event_lock);
|
|
|
|
if (0 != res) return 0;
|
2008-03-23 15:33:04 +03:00
|
|
|
|
|
|
|
if(!TAILQ_EMPTY(&base->sig.signalqueue))
|
|
|
|
evsignal_base = base;
|
2006-07-27 05:51:18 +04:00
|
|
|
done = 0;
|
|
|
|
while (!done && opal_event_enabled) {
|
|
|
|
/* Terminate the loop if we have been asked to */
|
|
|
|
if (base->event_gotterm) {
|
|
|
|
base->event_gotterm = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (base->event_break) {
|
|
|
|
base->event_break = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
/* You cannot use this interface for multi-threaded apps */
|
|
|
|
while (event_gotsig) {
|
|
|
|
event_gotsig = 0;
|
|
|
|
if (event_sigcb) {
|
|
|
|
res = (*event_sigcb)();
|
|
|
|
if (res == -1) {
|
|
|
|
errno = EINTR;
|
2008-03-23 15:33:04 +03:00
|
|
|
OPAL_THREAD_UNLOCK(&opal_event_lock);
|
|
|
|
return (-1);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
#if 0
|
|
|
|
/* OMPI: George wants to comment this out for now */
|
|
|
|
OPAL_THREAD_UNLOCK(&opal_event_lock);
|
|
|
|
timeout_correct(base, &tv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tv_p = &tv;
|
|
|
|
if (!base->event_count_active && !(flags & EVLOOP_NONBLOCK)) {
|
|
|
|
timeout_next(base, &tv_p);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* if we have active events, we just poll new events
|
|
|
|
* without waiting.
|
|
|
|
*/
|
|
|
|
evutil_timerclear(&tv);
|
|
|
|
}
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
/* If we have no events, we just exit */
|
2008-03-23 15:33:04 +03:00
|
|
|
if (!event_haveevents(base)) {
|
|
|
|
OPAL_THREAD_UNLOCK(&opal_event_lock);
|
|
|
|
event_debug(("%s: no events registered.", __func__));
|
|
|
|
return (1);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
opal_event_pipe_signalled = 0;
|
|
|
|
#endif
|
2008-03-23 15:33:04 +03:00
|
|
|
|
|
|
|
res = evsel->dispatch(base, evbase, tv_p);
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
opal_event_pipe_signalled = 1;
|
|
|
|
#endif
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
opal_output(0, "%s: ompi_evesel->dispatch() failed.", __func__);
|
2006-08-24 02:19:31 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&opal_event_lock);
|
2008-03-23 15:33:04 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
timeout_process(base);
|
|
|
|
|
|
|
|
if (base->event_count_active) {
|
2008-03-23 15:33:04 +03:00
|
|
|
event_process_active(base);
|
|
|
|
if (!base->event_count_active && (flags & (EVLOOP_ONCE|EVLOOP_ONELOOP)))
|
2006-07-27 05:51:18 +04:00
|
|
|
done = 1;
|
2008-03-23 15:33:04 +03:00
|
|
|
} else if (flags & (EVLOOP_NONBLOCK|EVLOOP_ONELOOP))
|
2006-07-27 05:51:18 +04:00
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
|
2006-08-14 18:52:39 +04:00
|
|
|
event_debug(("%s: asked to terminate loop.", __func__));
|
2008-03-23 15:33:04 +03:00
|
|
|
|
2006-08-24 02:19:31 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&opal_event_lock);
|
2006-07-27 05:51:18 +04:00
|
|
|
return (base->event_count_active);
|
|
|
|
#else
|
2008-03-23 15:33:04 +03:00
|
|
|
return 0;
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets up an event for processing once */
|
|
|
|
|
|
|
|
struct event_once {
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event ev;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
void (*cb)(int, short, void *);
|
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* One-time callback, it deletes itself */
|
|
|
|
|
|
|
|
static void
|
|
|
|
event_once_cb(int fd, short events, void *arg)
|
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event_once *eonce = arg;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
(*eonce->cb)(fd, events, eonce->arg);
|
|
|
|
free(eonce);
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
/* not threadsafe, event scheduled once. */
|
|
|
|
int
|
|
|
|
event_once(int fd, short events,
|
|
|
|
void (*callback)(int, short, void *), void *arg, struct timeval *tv)
|
|
|
|
{
|
|
|
|
return event_base_once(current_base, fd, events, callback, arg, tv);
|
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
/* Schedules an event once */
|
2006-07-27 05:51:18 +04:00
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_base_once(struct event_base *base, int fd, short events,
|
|
|
|
void (*callback)(int, short, void *), void *arg, struct timeval *tv)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
struct event_once *eonce;
|
|
|
|
struct timeval etv;
|
2008-03-23 15:33:04 +03:00
|
|
|
int res;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
/* We cannot support signals that just fire once */
|
2008-03-23 15:33:04 +03:00
|
|
|
if (events & EV_SIGNAL)
|
2006-07-27 05:51:18 +04:00
|
|
|
return (-1);
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if ((eonce = (struct event_once *)calloc(1, sizeof(struct event_once))) == NULL)
|
2006-07-27 05:51:18 +04:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
eonce->cb = callback;
|
|
|
|
eonce->arg = arg;
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (events == EV_TIMEOUT) {
|
2006-07-27 05:51:18 +04:00
|
|
|
if (tv == NULL) {
|
2008-03-23 15:33:04 +03:00
|
|
|
evutil_timerclear(&etv);
|
2006-07-27 05:51:18 +04:00
|
|
|
tv = &etv;
|
|
|
|
}
|
|
|
|
|
|
|
|
opal_evtimer_set(&eonce->ev, event_once_cb, eonce);
|
2008-03-23 15:33:04 +03:00
|
|
|
} else if (events & (EV_READ|EV_WRITE)) {
|
|
|
|
events &= EV_READ|EV_WRITE;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
event_set(&eonce->ev, fd, events, event_once_cb, eonce);
|
2006-07-27 05:51:18 +04:00
|
|
|
} else {
|
|
|
|
/* Bad event combination */
|
|
|
|
free(eonce);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
res = event_base_set(base, &eonce->ev);
|
|
|
|
if (res == 0)
|
|
|
|
res = event_add(&eonce->ev, tv);
|
|
|
|
if (res != 0) {
|
|
|
|
free(eonce);
|
|
|
|
return (res);
|
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-23 15:33:04 +03:00
|
|
|
event_set(struct event *ev, int fd, short events,
|
|
|
|
void (*callback)(int, short, void *), void *arg)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
/* Take the current base - caller needs to set the real base later */
|
|
|
|
ev->ev_base = current_base;
|
|
|
|
|
|
|
|
ev->ev_callback = callback;
|
|
|
|
ev->ev_arg = arg;
|
|
|
|
ev->ev_fd = fd;
|
|
|
|
ev->ev_events = events;
|
2008-03-23 15:33:04 +03:00
|
|
|
ev->ev_res = 0;
|
|
|
|
ev->ev_flags = EVLIST_INIT;
|
2006-07-27 05:51:18 +04:00
|
|
|
ev->ev_ncalls = 0;
|
|
|
|
ev->ev_pncalls = NULL;
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
min_heap_elem_init(ev);
|
|
|
|
|
2006-07-27 05:51:18 +04:00
|
|
|
/* by default, we put new events into the middle priority */
|
2008-03-23 15:33:04 +03:00
|
|
|
if(current_base)
|
|
|
|
ev->ev_pri = current_base->nactivequeues/2;
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_base_set(struct event_base *base, struct event *ev)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
/* Only innocent events may be assigned to a different base */
|
2008-03-23 15:33:04 +03:00
|
|
|
if (ev->ev_flags != EVLIST_INIT)
|
2006-07-27 05:51:18 +04:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
ev->ev_base = base;
|
|
|
|
ev->ev_pri = base->nactivequeues/2;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set's the priority of an event - if an event is already scheduled
|
|
|
|
* changing the priority is going to fail.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_priority_set(struct event *ev, int pri)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
if (ev->ev_flags & EVLIST_ACTIVE)
|
2006-07-27 05:51:18 +04:00
|
|
|
return (-1);
|
|
|
|
if (pri < 0 || pri >= ev->ev_base->nactivequeues)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
ev->ev_pri = pri;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if a specific event is pending or scheduled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
event_pending(struct event *ev, short event, struct timeval *tv)
|
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
struct timeval now, res;
|
2006-07-27 05:51:18 +04:00
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (ev->ev_flags & EVLIST_INSERTED)
|
|
|
|
flags |= (ev->ev_events & (EV_READ|EV_WRITE));
|
|
|
|
if (ev->ev_flags & EVLIST_ACTIVE)
|
|
|
|
flags |= ev->ev_res;
|
|
|
|
if (ev->ev_flags & EVLIST_TIMEOUT)
|
|
|
|
flags |= EV_TIMEOUT;
|
|
|
|
if (ev->ev_flags & EVLIST_SIGNAL)
|
|
|
|
flags |= EV_SIGNAL;
|
|
|
|
|
|
|
|
event &= (EV_TIMEOUT|EV_READ|EV_WRITE|EV_SIGNAL);
|
|
|
|
|
|
|
|
/* See if there is a timeout that we should report */
|
2008-03-23 15:33:04 +03:00
|
|
|
if (tv != NULL && (flags & event & EV_TIMEOUT)) {
|
|
|
|
gettime(&now);
|
|
|
|
evutil_timersub(&ev->ev_timeout, &now, &res);
|
|
|
|
/* correctly remap to real time */
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
evutil_timeradd(&now, &res, tv);
|
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
return (flags & event);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_add(struct event *ev, struct timeval *tv)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
struct event_base *base = ev->ev_base;
|
2008-03-23 15:33:04 +03:00
|
|
|
const struct eventop *evsel = base->evsel;
|
2006-07-27 05:51:18 +04:00
|
|
|
void *evbase = base->evbase;
|
2008-03-23 15:33:04 +03:00
|
|
|
int res = 0;
|
|
|
|
event_debug((
|
|
|
|
"event_add: event: %p, %s%s%scall %p",
|
|
|
|
ev,
|
|
|
|
ev->ev_events & EV_READ ? "EV_READ " : " ",
|
|
|
|
ev->ev_events & EV_WRITE ? "EV_WRITE " : " ",
|
|
|
|
tv ? "EV_TIMEOUT " : " ",
|
|
|
|
ev->ev_callback));
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
assert(!(ev->ev_flags & ~EVLIST_ALL));
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
if (tv != NULL) {
|
|
|
|
struct timeval now;
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (ev->ev_flags & EVLIST_TIMEOUT)
|
|
|
|
event_queue_remove(base, ev, EVLIST_TIMEOUT);
|
|
|
|
else if (min_heap_reserve(&base->timeheap,
|
|
|
|
1 + min_heap_size(&base->timeheap)) == -1)
|
|
|
|
return (-1); /* ENOMEM == errno */
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
/* Check if it is active due to a timeout. Rescheduling
|
|
|
|
* this timeout before the callback can be executed
|
|
|
|
* removes it from the active list. */
|
2008-03-23 15:33:04 +03:00
|
|
|
if ((ev->ev_flags & EVLIST_ACTIVE) &&
|
|
|
|
(ev->ev_res & EV_TIMEOUT)) {
|
2006-07-27 05:51:18 +04:00
|
|
|
/* See if we are just active executing this
|
|
|
|
* event in a loop
|
|
|
|
*/
|
|
|
|
if (ev->ev_ncalls && ev->ev_pncalls) {
|
|
|
|
/* Abort loop */
|
|
|
|
*ev->ev_pncalls = 0;
|
|
|
|
}
|
2008-03-23 15:33:04 +03:00
|
|
|
|
|
|
|
event_queue_remove(base, ev, EVLIST_ACTIVE);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
gettime(&now);
|
|
|
|
evutil_timeradd(&now, tv, &ev->ev_timeout);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
event_debug((
|
2008-03-23 15:33:04 +03:00
|
|
|
"event_add: timeout in %d seconds, call %p",
|
|
|
|
tv->tv_sec, ev->ev_callback));
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
event_queue_insert(base, ev, EVLIST_TIMEOUT);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if ((ev->ev_events & (EV_READ|EV_WRITE)) &&
|
|
|
|
!(ev->ev_flags & (EVLIST_INSERTED|EVLIST_ACTIVE))) {
|
|
|
|
res = evsel->add(evbase, ev);
|
|
|
|
if (res != -1)
|
|
|
|
event_queue_insert(base, ev, EVLIST_INSERTED);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
return (res);
|
|
|
|
} else if ((ev->ev_events & EV_SIGNAL) &&
|
|
|
|
!(ev->ev_flags & EVLIST_SIGNAL)) {
|
|
|
|
res = evsel->add(evbase, ev);
|
|
|
|
if (res != -1)
|
|
|
|
event_queue_insert(base, ev, EVLIST_SIGNAL);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
if(opal_using_threads() && opal_event_pipe_signalled == 0) {
|
2008-03-23 15:33:04 +03:00
|
|
|
unsigned char byte = 0;
|
|
|
|
if(write(opal_event_pipe[1], &byte, 1) != 1)
|
|
|
|
opal_output(0, "opal_event_add: write() to opal_event_pipe[1] failed with errno=%d\n", errno);
|
|
|
|
opal_event_pipe_signalled++;
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
#endif
|
2008-03-23 15:33:04 +03:00
|
|
|
return res;
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-23 15:33:04 +03:00
|
|
|
event_del(struct event *ev)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
int rc = 0;
|
2006-07-27 05:51:18 +04:00
|
|
|
struct event_base *base;
|
2008-03-23 15:33:04 +03:00
|
|
|
const struct eventop *evsel;
|
2006-07-27 05:51:18 +04:00
|
|
|
void *evbase;
|
|
|
|
|
|
|
|
event_debug(("event_del: %p, callback %p",
|
|
|
|
ev, ev->ev_callback));
|
|
|
|
|
|
|
|
/* An event without a base has not been added */
|
|
|
|
if (ev->ev_base == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
base = ev->ev_base;
|
|
|
|
evsel = base->evsel;
|
|
|
|
evbase = base->evbase;
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
assert(!(ev->ev_flags & ~EVLIST_ALL));
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
/* See if we are just active executing this event in a loop */
|
|
|
|
if (ev->ev_ncalls && ev->ev_pncalls) {
|
|
|
|
/* Abort loop */
|
|
|
|
*ev->ev_pncalls = 0;
|
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (ev->ev_flags & EVLIST_TIMEOUT)
|
|
|
|
event_queue_remove(base, ev, EVLIST_TIMEOUT);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (ev->ev_flags & EVLIST_ACTIVE)
|
|
|
|
event_queue_remove(base, ev, EVLIST_ACTIVE);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (ev->ev_flags & EVLIST_INSERTED) {
|
|
|
|
event_queue_remove(base, ev, EVLIST_INSERTED);
|
2006-07-27 05:51:18 +04:00
|
|
|
rc = (evsel->del(evbase, ev));
|
2008-03-23 15:33:04 +03:00
|
|
|
} else if (ev->ev_flags & EVLIST_SIGNAL) {
|
|
|
|
event_queue_remove(base, ev, EVLIST_SIGNAL);
|
2006-07-27 05:51:18 +04:00
|
|
|
rc = (evsel->del(evbase, ev));
|
|
|
|
}
|
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
2008-03-23 15:33:04 +03:00
|
|
|
if(opal_using_threads() && opal_event_pipe_signalled == 0) {
|
|
|
|
unsigned char byte = 0;
|
|
|
|
if(write(opal_event_pipe[1], &byte, 1) != 1)
|
|
|
|
opal_output(0, "opal_event_add: write() to opal_event_pipe[1] failed with errno=%d\n", errno);
|
|
|
|
opal_event_pipe_signalled++;
|
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
void
|
|
|
|
event_active(struct event *ev, int res, short ncalls)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
/* We get different kinds of events, add them together */
|
2008-03-23 15:33:04 +03:00
|
|
|
if (ev->ev_flags & EVLIST_ACTIVE) {
|
2006-07-27 05:51:18 +04:00
|
|
|
ev->ev_res |= res;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev->ev_res = res;
|
|
|
|
ev->ev_ncalls = ncalls;
|
|
|
|
ev->ev_pncalls = NULL;
|
2008-03-23 15:33:04 +03:00
|
|
|
event_queue_insert(ev->ev_base, ev, EVLIST_ACTIVE);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-03-23 15:33:04 +03:00
|
|
|
timeout_next(struct event_base *base, struct timeval **tv_p)
|
|
|
|
{
|
|
|
|
struct timeval now = OPAL_TIMEOUT_DEFAULT;
|
|
|
|
struct event *ev;
|
|
|
|
struct timeval *tv = *tv_p;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if ((ev = min_heap_top(&base->timeheap)) == NULL) {
|
|
|
|
/* if no time-based events are active wait for I/O */
|
|
|
|
*tv = now;
|
2006-07-27 05:51:18 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (gettime(&now) == -1)
|
|
|
|
return (-1);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (evutil_timercmp(&ev->ev_timeout, &now, <=)) {
|
|
|
|
evutil_timerclear(tv);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
evutil_timersub(&ev->ev_timeout, &now, tv);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
assert(tv->tv_sec >= 0);
|
|
|
|
assert(tv->tv_usec >= 0);
|
|
|
|
|
|
|
|
event_debug(("timeout_next: in %d seconds", tv->tv_sec));
|
2008-03-23 15:33:04 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Let's not delete this yet, but it doesn't look necessary right now */
|
|
|
|
/*
|
|
|
|
* Determines if the time is running backwards by comparing the current
|
|
|
|
* time against the last time we checked. Not needed when using clock
|
|
|
|
* monotonic.
|
|
|
|
*/
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
static void
|
2008-03-23 15:33:04 +03:00
|
|
|
timeout_correct(struct event_base *base, struct timeval *tv)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
struct event **pev;
|
|
|
|
unsigned int size;
|
|
|
|
struct timeval off;
|
|
|
|
|
|
|
|
if (use_monotonic)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check if time is running backwards */
|
|
|
|
gettime(tv);
|
|
|
|
if (evutil_timercmp(tv, &base->event_tv, >=)) {
|
|
|
|
base->event_tv = *tv;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event_debug(("%s: time is running backwards, corrected",
|
|
|
|
__func__));
|
|
|
|
evutil_timersub(&base->event_tv, tv, &off);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We can modify the key element of the node without destroying
|
|
|
|
* the key, beause we apply it to all in the right order.
|
|
|
|
*/
|
2008-03-23 15:33:04 +03:00
|
|
|
pev = base->timeheap.p;
|
|
|
|
size = base->timeheap.n;
|
|
|
|
for (; size-- > 0; ++pev) {
|
|
|
|
struct timeval *ev_tv = &(**pev).ev_timeout;
|
|
|
|
evutil_timersub(ev_tv, &off, ev_tv);
|
|
|
|
}
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
2008-03-23 15:33:04 +03:00
|
|
|
#endif
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
void
|
2006-07-27 05:51:18 +04:00
|
|
|
timeout_process(struct event_base *base)
|
|
|
|
{
|
2008-03-23 15:33:04 +03:00
|
|
|
struct timeval now;
|
|
|
|
struct event *ev;
|
|
|
|
|
|
|
|
if (min_heap_empty(&base->timeheap))
|
|
|
|
return;
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
gettime(&now);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
while ((ev = min_heap_top(&base->timeheap))) {
|
|
|
|
if (evutil_timercmp(&ev->ev_timeout, &now, >))
|
2006-07-27 05:51:18 +04:00
|
|
|
break;
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
/* delete this event from the I/O queues */
|
|
|
|
event_del(ev);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
|
|
|
event_debug(("timeout_process: call %p",
|
|
|
|
ev->ev_callback));
|
2008-03-23 15:33:04 +03:00
|
|
|
event_active(ev, EV_TIMEOUT, 1);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-23 15:33:04 +03:00
|
|
|
event_queue_remove(struct event_base *base, struct event *ev, int queue)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
if (!(ev->ev_flags & queue))
|
|
|
|
event_errx(1, "%s: %p(fd %d) not on queue %x", __func__,
|
2008-03-23 15:33:04 +03:00
|
|
|
(void*)ev, ev->ev_fd, queue);
|
2006-07-27 05:51:18 +04:00
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (~ev->ev_flags & EVLIST_INTERNAL)
|
2006-07-27 05:51:18 +04:00
|
|
|
base->event_count--;
|
|
|
|
|
|
|
|
ev->ev_flags &= ~queue;
|
|
|
|
switch (queue) {
|
2008-03-23 15:33:04 +03:00
|
|
|
case EVLIST_ACTIVE:
|
|
|
|
base->event_count_active--;
|
2006-07-27 05:51:18 +04:00
|
|
|
TAILQ_REMOVE(base->activequeues[ev->ev_pri],
|
|
|
|
ev, ev_active_next);
|
|
|
|
break;
|
2008-03-23 15:33:04 +03:00
|
|
|
case EVLIST_SIGNAL:
|
|
|
|
TAILQ_REMOVE(&base->sig.signalqueue, ev, ev_signal_next);
|
2006-07-27 05:51:18 +04:00
|
|
|
break;
|
2008-03-23 15:33:04 +03:00
|
|
|
case EVLIST_TIMEOUT:
|
|
|
|
min_heap_erase(&base->timeheap, ev);
|
2006-07-27 05:51:18 +04:00
|
|
|
break;
|
2008-03-23 15:33:04 +03:00
|
|
|
case EVLIST_INSERTED:
|
2006-07-27 05:51:18 +04:00
|
|
|
TAILQ_REMOVE(&base->eventqueue, ev, ev_next);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
event_errx(1, "%s: unknown queue %x", __func__, queue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-23 15:33:04 +03:00
|
|
|
event_queue_insert(struct event_base *base, struct event *ev, int queue)
|
2006-07-27 05:51:18 +04:00
|
|
|
{
|
|
|
|
if (ev->ev_flags & queue) {
|
|
|
|
/* Double insertion is possible for active events */
|
2008-03-23 15:33:04 +03:00
|
|
|
if (queue & EVLIST_ACTIVE)
|
2006-07-27 05:51:18 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
event_errx(1, "%s: %p(fd %d) already on queue %x", __func__,
|
2008-03-23 15:33:04 +03:00
|
|
|
(void*)ev, ev->ev_fd, queue);
|
2006-07-27 05:51:18 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 15:33:04 +03:00
|
|
|
if (~ev->ev_flags & EVLIST_INTERNAL)
|
2006-07-27 05:51:18 +04:00
|
|
|
base->event_count++;
|
|
|
|
|
|
|
|
ev->ev_flags |= queue;
|
|
|
|
switch (queue) {
|
2008-03-23 15:33:04 +03:00
|
|
|
case EVLIST_ACTIVE:
|
|
|
|
base->event_count_active++;
|
2006-07-27 05:51:18 +04:00
|
|
|
TAILQ_INSERT_TAIL(base->activequeues[ev->ev_pri],
|
|
|
|
ev,ev_active_next);
|
|
|
|
break;
|
2008-03-23 15:33:04 +03:00
|
|
|
case EVLIST_SIGNAL:
|
|
|
|
TAILQ_INSERT_TAIL(&base->sig.signalqueue, ev, ev_signal_next);
|
2006-07-27 05:51:18 +04:00
|
|
|
break;
|
2008-03-23 15:33:04 +03:00
|
|
|
case EVLIST_TIMEOUT: {
|
|
|
|
min_heap_push(&base->timeheap, ev);
|
2006-07-27 05:51:18 +04:00
|
|
|
break;
|
|
|
|
}
|
2008-03-23 15:33:04 +03:00
|
|
|
case EVLIST_INSERTED:
|
2006-07-27 05:51:18 +04:00
|
|
|
TAILQ_INSERT_TAIL(&base->eventqueue, ev, ev_next);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
event_errx(1, "%s: unknown queue %x", __func__, queue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Functions for debugging */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
event_get_version(void)
|
|
|
|
{
|
|
|
|
return ("OpenMPI");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No thread-safe interface needed - the information should be the same
|
|
|
|
* for all threads.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *
|
|
|
|
event_get_method(void)
|
|
|
|
{
|
|
|
|
return (current_base->evsel->name);
|
|
|
|
}
|