This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Triton Repository". The branch, master has been updated via b540d82e6742c81af5a516448aff121caac45d94 (commit) from d971682ce443fb65a5c569f0909d4010a83e9683 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b540d82e6742c81af5a516448aff121caac45d94 Author: Phil Carns <pcarns@carns-x220.(none)> Date: Thu Jul 28 12:04:56 2011 -0400 remove raw epoll support, use libev only re #133 ----------------------------------------------------------------------- Summary of changes: code/Makefile.in | 4 - code/src/aesop/resource.c | 395 +------------------------ code/src/aesop/resource.h | 2 - code/src/common/resources/aesocket/aesocket.c | 175 ----------- code/src/common/resources/timer/timer.c | 109 +------- 5 files changed, 5 insertions(+), 680 deletions(-) Diff of changes: diff --git a/code/Makefile.in b/code/Makefile.in index 10fc5a0..6e01c2f 100644 --- a/code/Makefile.in +++ b/code/Makefile.in @@ -95,10 +95,6 @@ LIBCFLAGS=@LIBCFLAGS@ # in the module.mk.in because we need it to take effect when the .d file is # generated as well. LIBCFLAGS += -DEV_CONFIG_H=\"triton-config.h\" -# switch which of the following two lines is commented if you want to -# disable libev and go back to using epoll for the aesop polling strategy -#LIBCFLAGS += -D__AESOP_EPOLL -LIBCFLAGS += -D__AESOP_LIBEV LDFLAGS += @LDFLAGS@ LIBS += @LIBS@ -lcrypto diff --git a/code/src/aesop/resource.c b/code/src/aesop/resource.c index bc4619f..b2a5309 100644 --- a/code/src/aesop/resource.c +++ b/code/src/aesop/resource.c @@ -1,16 +1,4 @@ -#if !defined (__AESOP_EPOLL) && !defined (__AESOP_LIBEV) -#error Must define one of __AESOP_EPOLL or __AESOP_LIBEV -#endif -#if defined (__AESOP_EPOLL) && defined (__AESOP_LIBEV) -#error Must define exactly one of __AESOP_EPOLL or __AESOP_LIBEV, not both -#endif - -#ifdef __AESOP_EPOLL -#include <sys/epoll.h> -#endif -#ifdef __AESOP_LIBEV #include "src/common/libev/ev.h" -#endif #include <stddef.h> #include <unistd.h> #include <fcntl.h> @@ -21,12 +9,7 @@ struct ae_poll_data { -#ifdef __AESOP_EPOLL - int pipe_fds[2]; -#endif -#ifdef __AESOP_LIBEV ev_async async; -#endif triton_ret_t (*poll_context)(ae_context_t context); ae_context_t context; }; @@ -42,14 +25,8 @@ triton_debug_mask_t aesop_debug_cancel_mask; static int ae_resource_count = 0; static struct ae_resource_entry ae_resource_entries[AE_MAX_RESOURCES]; -#ifdef __AESOP_EPOLL -static int efd = -1; -struct ae_poll_data break_target; -#endif -#ifdef __AESOP_LIBEV static struct ev_loop *eloop = NULL; ev_async eloop_breaker; -#endif static pthread_t ev_loop_thread; #define AE_RESOURCE_IDX2ID(reindex) (reindex+16) @@ -61,99 +38,13 @@ struct ae_context int resource_count; int* resource_ids; struct ae_poll_data* poll_data; -#ifdef __AESOP_EPOLL - struct ae_poll_data break_target; - int efd; -#endif -#ifdef __AESOP_LIBEV struct ev_loop *eloop; ev_async eloop_breaker; -#endif }; static int ae_context_count = 0; static struct ae_context ae_context_entries[AE_MAX_CONTEXTS]; -#ifdef __AESOP_EPOLL -triton_ret_t ae_resource_register(struct ae_resource *resource, int *newid) -{ - int reindex = ae_resource_count; - int ret; - struct epoll_event event; - - if(efd < 0) - { - /* This is the first resource to be registered. Initialize the - * epoll fd and create a pipe that can be used to break the epoll - * wait. - */ - efd = epoll_create(32); - if(efd < 0) - { - triton_err(triton_log_default, "Error: could not create epoll fd for resource polling.\n"); - return(TRITON_ERR_EPOLL); - } - ret = pipe(break_target.pipe_fds); - if(ret < 0) - { - triton_err(triton_log_default, "Error: could not create pipe for resource polling.\n"); - close(efd); - return(TRITON_ERR_EPOLL); - } - fcntl(break_target.pipe_fds[0], F_SETFL, O_NONBLOCK); - fcntl(break_target.pipe_fds[1], F_SETFL, O_NONBLOCK); - break_target.context = NULL; - break_target.poll_context = NULL; - event.data.ptr = &break_target; - event.events = EPOLLIN; - ret = epoll_ctl(efd, EPOLL_CTL_ADD, break_target.pipe_fds[0], &event); - if(ret < 0) - { - triton_err(triton_log_default, "Error: could not epoll fd for resource polling.\n"); - close(efd); - close(break_target.pipe_fds[0]); - close(break_target.pipe_fds[1]); - return(TRITON_ERR_EPOLL); - } - } - - if(ae_resource_count == AE_MAX_RESOURCES) - { - return TRITON_ERR_INVAL; - } - - ret = pipe(ae_resource_entries[reindex].poll_data.pipe_fds); - if(ret < 0) - { - triton_err(triton_log_default, "Error: could not create pipe for resource polling.\n"); - return(TRITON_ERR_EPOLL); - - } - fcntl(ae_resource_entries[reindex].poll_data.pipe_fds[0], F_SETFL, O_NONBLOCK); - fcntl(ae_resource_entries[reindex].poll_data.pipe_fds[1], F_SETFL, O_NONBLOCK); - ae_resource_entries[reindex].poll_data.poll_context = - resource->poll_context; - ae_resource_entries[reindex].poll_data.context = NULL; - event.data.ptr = &ae_resource_entries[reindex].poll_data; - event.events = EPOLLIN; - ret = epoll_ctl(efd, EPOLL_CTL_ADD, - ae_resource_entries[reindex].poll_data.pipe_fds[0], &event); - if(ret < 0) - { - triton_err(triton_log_default, "Error: could not epoll fd for resource polling.\n"); - return(TRITON_ERR_EPOLL); - - } - - ae_resource_entries[reindex].id = AE_RESOURCE_IDX2ID(reindex); - ae_resource_entries[reindex].resource = resource; - ae_resource_count++; - *newid = AE_RESOURCE_IDX2ID(reindex); - return TRITON_SUCCESS; -} -#endif /* __AESOP_EPOLL */ - -#ifdef __AESOP_LIBEV static void ev_break_cb(EV_P_ ev_async *w, int revents) { /* Break the loop. Note that ev_run() will still process all events @@ -216,7 +107,6 @@ triton_ret_t ae_resource_register(struct ae_resource *resource, int *newid) *newid = AE_RESOURCE_IDX2ID(reindex); return TRITON_SUCCESS; } -#endif /* __AESOP_LIBEV */ void ae_resource_unregister(int id) { @@ -226,15 +116,7 @@ void ae_resource_unregister(int id) * just assume that contexts are always closed before resources are * unregistered? */ -#ifdef __AESOP_EPOLL - epoll_ctl(efd, EPOLL_CTL_DEL, - ae_resource_entries[idx].poll_data.pipe_fds[0], NULL); - close(ae_resource_entries[idx].poll_data.pipe_fds[0]); - close(ae_resource_entries[idx].poll_data.pipe_fds[1]); -#endif -#ifdef __AESOP_LIBEV ev_async_stop(eloop, &ae_resource_entries[idx].poll_data.async); -#endif if(idx != (ae_resource_count -1)) { @@ -245,92 +127,6 @@ void ae_resource_unregister(int id) ae_resource_count--; } -#ifdef __AESOP_EPOLL - -/** - * ae_poll_break() can be used to interrupt a currently executing ae_poll - * call. This would typically be used in the linkage between c and aesop - * functions to allow the c program to continue execution after the final - * aesop callback has completed. - */ -void ae_poll_break(ae_context_t context) -{ - int write_pipe = -1; - char onebyte; - - if(pthread_equal(ev_loop_thread, pthread_self())) - { - /* this was called from the event loop thread, so we know that it is - * already awake - */ - return; - } - - if(context) - { - write_pipe = context->break_target.pipe_fds[1]; - } - else - { - write_pipe = break_target.pipe_fds[1]; - } - - write(write_pipe, &onebyte, 1); -} - -/** - * ae_resource_request_poll() is used by a resource to inform aesop that the - * resource needs to be polled. - */ -/* TODO: think about race conditions. Need any locking here? */ -void ae_resource_request_poll(ae_context_t context, int resource_id) -{ - int write_pipe = -1; - int i; - int ridx; - char onebyte = '0'; - - if(context) - { - /* find this resource in the context */ - for(i=0; i<context->resource_count; i++) - { - if(resource_id == context->resource_ids[i]) - { - write_pipe = context->poll_data[i].pipe_fds[1]; - break; - } - } - } - else - { - /* find this resource in the global list */ - ridx = AE_RESOURCE_ID2IDX(resource_id); - write_pipe = ae_resource_entries[ridx].poll_data.pipe_fds[1]; - } - - if(write_pipe < 0) - { - triton_err(triton_log_default, "Error: context %p is not configured to handle resource with id %d", context, resource_id); - for(i=0; i<ae_resource_count; i++) - { - if(ae_resource_entries[i].id == resource_id) - { - triton_err(triton_log_default, "Consider adding the \"%s\" resource your aesop context.", ae_resource_entries[i].resource->resource_name); - assert(0); - } - } - triton_err(triton_log_default, "Error: resource_id %d is unknown to aesop. Are you using a resource that was not initialized?\n", resource_id); - assert(0); - } - - write(write_pipe, &onebyte, 1); - return; -} -#endif /* __AESOP_EPOLL */ - -#ifdef __AESOP_LIBEV - static void find_async_watcher(ae_context_t context, int resource_id, ev_async** async_out, struct ev_loop** loop_out) { ev_async* async = NULL; @@ -430,7 +226,6 @@ void ae_resource_request_poll(ae_context_t context, int resource_id) return; } -#endif /* __AESOP_LIBEV */ /** * ae_cancel_op tries to cancel the operation with the given id. This @@ -622,106 +417,6 @@ void ae_backtrace(void) #include <assert.h> -#ifdef __AESOP_EPOLL -#define AE_PIPE_READ_SIZE 128 - -triton_ret_t ae_poll(ae_context_t context, int millisecs) -{ - triton_ret_t tret; - int to_poll; - int ret; - struct epoll_event* events; - int event_count; - int i; - struct ae_poll_data* poll_data; - - if(context) - { - /* use context specific epoll fd */ - to_poll = context->efd; - event_count = context->resource_count + 1; - } - else - { - /* use global epoll fd */ - if(efd < 0) - { - /* nothing to poll yet */ - return(TRITON_SUCCESS); - } - to_poll = efd; - event_count = ae_resource_count + 1; - } - - events = malloc(sizeof(*events) * event_count); - if(!events) - { - return(TRITON_ERR_NOMEM); - } - - /* wait for a resource to indicate that it has something to do */ - event_count = epoll_wait(to_poll, events, event_count, millisecs); - - - /* if interrupted, just exit and let the caller try again */ - if(event_count < 0 && errno == EINTR) - { - free(events); - return(TRITON_SUCCESS); - } - - /* general error */ - if(event_count < 0) - { - free(events); - triton_err(triton_log_default, "Error: could not epoll_wait for resource polling.\n"); - return(TRITON_ERR_EPOLL); - } - - /* this means that the epoll timed out without finding any work */ - if(event_count == 0) - { - free(events); - return(TRITON_ERR_TIMEDOUT); - } - - /* poll each resource that needs attention */ - for(i=0; i<event_count; i++) - { - char pipebuf[AE_PIPE_READ_SIZE]; - - poll_data = (struct ae_poll_data*)events[i].data.ptr; - assert(poll_data); - /* empty the pipe (short reads are ok) */ - if(poll_data->pipe_fds[1] != 0) /* skip non-pipes */ - { - do - { - ret = read(events[i].data.fd, pipebuf, AE_PIPE_READ_SIZE); - } while(ret >= 1 && ret < AE_PIPE_READ_SIZE); - } - - if(poll_data->poll_context) - { - tret = poll_data->poll_context(context); - if(tret != TRITON_SUCCESS) - { - free(events); - return(tret); - } - } - else - { - /* we were just signalled to wake up; no work to do */ - } - } - - free(events); - return(TRITON_SUCCESS); -} -#endif /* __AESOP_EPOLL */ - -#ifdef __AESOP_LIBEV static void timeout_cb(EV_P_ ev_timer *w, int revents) { int* hit_timeout = (int*)w->data; @@ -773,7 +468,6 @@ triton_ret_t ae_poll(ae_context_t context, int millisecs) return(TRITON_SUCCESS); } -#endif /* __AESOP_LIBEV */ #include <stdarg.h> @@ -785,10 +479,6 @@ triton_ret_t _ae_context_create(ae_context_t *context, const char *format __attr ae_context_t c; int i, j, reindex; triton_ret_t ret; -#ifdef __AESOP_EPOLL - struct epoll_event event; - int ep_ret; -#endif if(ae_context_count == AE_MAX_CONTEXTS) { @@ -811,7 +501,6 @@ triton_ret_t _ae_context_create(ae_context_t *context, const char *format __attr return TRITON_ERR_NOMEM; } -#ifdef __AESOP_LIBEV c->eloop = ev_loop_new(EVFLAG_AUTO); if(!c->eloop) { @@ -822,43 +511,7 @@ triton_ret_t _ae_context_create(ae_context_t *context, const char *format __attr } ev_async_init(&c->eloop_breaker, ev_break_cb); ev_async_start(c->eloop, &c->eloop_breaker); -#endif -#ifdef __AESOP_EPOLL - c->efd = epoll_create(32); - if(c->efd < 0) - { - triton_err(triton_log_default, "Error: could not create epoll fd for resource polling.\n"); - free(c->resource_ids); - free(c->poll_data); - return(TRITON_ERR_EPOLL); - } - ep_ret = pipe(c->break_target.pipe_fds); - if(ep_ret < 0) - { - triton_err(triton_log_default, "Error: could not create pipe for resource polling.\n"); - close(c->efd); - free(c->resource_ids); - free(c->poll_data); - return(TRITON_ERR_EPOLL); - } - fcntl(c->break_target.pipe_fds[0], F_SETFL, O_NONBLOCK); - fcntl(c->break_target.pipe_fds[1], F_SETFL, O_NONBLOCK); - c->break_target.context = c; - c->break_target.poll_context = NULL; - event.data.ptr = &c->break_target; - event.events = EPOLLIN; - ep_ret = epoll_ctl(c->efd, EPOLL_CTL_ADD, c->break_target.pipe_fds[0], &event); - if(ep_ret < 0) - { - triton_err(triton_log_default, "Error: could not epoll fd for resource polling.\n"); - close(c->efd); - close(c->break_target.pipe_fds[0]); - close(c->break_target.pipe_fds[1]); - free(c->resource_ids); - free(c->poll_data); - return(TRITON_ERR_EPOLL); - } -#endif + reindex = 0; /* step through the resource names passed in and register the context with them */ @@ -874,20 +527,7 @@ triton_ret_t _ae_context_create(ae_context_t *context, const char *format __attr { if(!strcmp(ae_resource_entries[j].resource->resource_name, rname)) { -#ifdef __AESOP_EPOLL - ep_ret = pipe(c->poll_data[reindex].pipe_fds); - if(ep_ret < 0) - { - /* TODO: clean up better here */ - triton_err(triton_log_default, "Error: could not create pipe for resource polling.\n"); - return(TRITON_ERR_EPOLL); - } - fcntl(c->poll_data[reindex].pipe_fds[0], F_SETFL, O_NONBLOCK); - fcntl(c->poll_data[reindex].pipe_fds[1], F_SETFL, O_NONBLOCK); -#endif -#ifdef __AESOP_LIBEV ev_async_init(&c->poll_data[reindex].async, ev_async_cb); -#endif c->poll_data[reindex].poll_context = ae_resource_entries[j].poll_data.poll_context; c->poll_data[reindex].context = c; @@ -902,23 +542,7 @@ triton_ret_t _ae_context_create(ae_context_t *context, const char *format __attr return ret; } } - -#ifdef __AESOP_EPOLL - /* monitor the context-specific pipe */ - event.data.ptr = &c->poll_data[reindex]; - event.events = EPOLLIN; - ep_ret = epoll_ctl(c->efd, EPOLL_CTL_ADD, - c->poll_data[reindex].pipe_fds[0], &event); - if(ep_ret < 0 && errno != EEXIST) - { - /* TODO: clean up better here */ - triton_err(triton_log_default, "Error: could not epoll fd for resource polling.\n"); - return(TRITON_ERR_EPOLL); - } -#endif -#ifdef __AESOP_LIBEV ev_async_start(c->eloop, &c->poll_data[reindex].async); -#endif c->resource_ids[reindex] = ae_resource_entries[j].id; @@ -952,15 +576,7 @@ triton_ret_t ae_context_destroy(ae_context_t context) { ae_resource_entries[idx].resource->unregister_context(context); } -#ifdef __AESOP_EPOLL - if(context->poll_data[i].pipe_fds[0] >= 0) - close(context->poll_data[i].pipe_fds[0]); - if(context->poll_data[i].pipe_fds[1] >= 0) - close(context->poll_data[i].pipe_fds[1]); -#endif -#ifdef __AESOP_LIBEV ev_async_stop(context->eloop, &context->poll_data[i].async); -#endif } free(context->resource_ids); free(context->poll_data); @@ -968,12 +584,7 @@ triton_ret_t ae_context_destroy(ae_context_t context) context->poll_data = NULL; context->id = -1; context->resource_count = -1; -#ifdef __AESOP_EPOLL - close(context->efd); -#endif -#ifdef __AESOP_LIBEV ev_loop_destroy(context->eloop); -#endif return TRITON_SUCCESS; } @@ -1099,7 +710,7 @@ triton_ret_t ae_error_wrap_stack(struct ae_ctl *ctl, triton_ret_t parent) return ret; } -#ifdef __AESOP_LIBEV + struct ev_loop * ae_resource_get_eloop(ae_context_t context) { if(!context) @@ -1107,8 +718,6 @@ struct ev_loop * ae_resource_get_eloop(ae_context_t context) else return(context->eloop); } -#endif - /* * Local variables: diff --git a/code/src/aesop/resource.h b/code/src/aesop/resource.h index 2a0bc53..b4d30b0 100644 --- a/code/src/aesop/resource.h +++ b/code/src/aesop/resource.h @@ -62,12 +62,10 @@ void ae_resource_unregister(int resource_id); void ae_resource_request_poll(ae_context_t context, int resource_id); /* Called by c programs to break ae_poll() calls once callbacks are complete */ void ae_poll_break(ae_context_t context); -#ifdef __AESOP_LIBEV /* this function is used by resources that want access to the event loop * used by aesop for this context */ struct ev_loop * ae_resource_get_eloop(ae_context_t context); -#endif /* Contexts are created to allow separation of polling for different logical * groups of operations. Don't use this function. Instead, use the associated diff --git a/code/src/common/resources/aesocket/aesocket.c b/code/src/common/resources/aesocket/aesocket.c index 3b0f6f0..ba3ec76 100644 --- a/code/src/common/resources/aesocket/aesocket.c +++ b/code/src/common/resources/aesocket/aesocket.c @@ -8,36 +8,7 @@ #include <pthread.h> #include <unistd.h> -#ifdef __AESOP_LIBEV #include "src/common/libev/ev.h" -#endif -#ifdef __AESOP_EPOLL -#include <sys/epoll.h> -#endif - -/* TODO: Hack: so that we can modify the pipe fd used by this resource - * (resources normally don't have the definition of these structs) - */ -#ifdef __AESOP_EPOLL -struct ae_poll_data -{ -#ifdef __AESOP_EPOLL - int pipe_fds[2]; -#endif -#ifdef __AESOP_LIBEV - ev_async async; -#endif - triton_ret_t (*poll_context)(ae_context_t context); - ae_context_t context; -}; - -struct ae_resource_entry -{ - int id; - struct ae_poll_data poll_data; - struct ae_resource *resource; -}; -#endif struct ae_context { @@ -45,14 +16,8 @@ struct ae_context int resource_count; int* resource_ids; struct ae_poll_data* poll_data; -#ifdef __AESOP_EPOLL - struct ae_poll_data break_target; - int efd; -#endif -#ifdef __AESOP_LIBEV struct ev_loop *eloop; ev_async eloop_breaker; -#endif }; @@ -72,61 +37,16 @@ struct aesocket_op triton_ret_t tret; int fd; int flags; -#ifdef __AESOP_LIBEV ev_io io; -#endif }; -#ifdef __AESOP_LIBEV static ae_ops_t posted_oplist; static ae_ops_t inflight_oplist; static ae_ops_t cancelled_oplist; static pthread_t event_loop_thread; -#else -static pthread_t epoll_thread; -static int epoll_thread_running = 0; -static int epfd = -1; - -static void* thread_fn(void* foo) -{ - struct epoll_event events[64]; - int count; - struct ae_op *op; - struct aesocket_op *socket_op; - int i; - int ret; - - do - { - if(epoll_thread_running) - count = epoll_wait(epfd, events, 64, -1); - else - count = epoll_wait(epfd, events, 64, 0); - - /* TODO: error handling */ - assert(count >= 0); - - for(i=0; i<count; i++) - { - op = (struct ae_op*)events[i].data.ptr; - socket_op = ae_op_entry(op, struct aesocket_op, op); -/* NOTE: this isn't necessary now because we are using one shot events */ -#if 0 - ret = epoll_ctl(epfd, EPOLL_CTL_DEL, socket_op->fd, NULL); - /* TODO: error handling */ - assert(count >= 0); -#endif - ae_opcache_complete_op(aesocket_opcache, op, triton_ret_t, TRITON_SUCCESS); - } - }while(epoll_thread_running); - - return(NULL); -} -#endif static triton_mutex_t aesocket_mutex = TRITON_MUTEX_INITIALIZER; -#ifdef __AESOP_LIBEV static void aesocket_fd_ready( EV_P_ ev_io * io, int revents) @@ -144,19 +64,13 @@ static void aesocket_fd_ready( ae_opcache_complete_op(aesocket_opcache, op, triton_ret_t, TRITON_SUCCESS); return; } -#endif ae_define_post(triton_ret_t, triton_aesocket_ready, int fd, int mode) { struct ae_op *op; struct aesocket_op *socket_op; -#ifdef __AESOP_LIBEV struct ev_loop *eloop; -#else - struct epoll_event event; - int ret; -#endif if (!aesocket_opcache) { @@ -174,19 +88,13 @@ ae_define_post(triton_ret_t, triton_aesocket_ready, int fd, ae_id_gen(triton_aesocket_resource_id, (intptr_t) op); socket_op->tret = TRITON_SUCCESS; socket_op->fd = fd; -#ifdef __AESOP_LIBEV socket_op->flags = (mode & AESOCKET_READ ? EV_READ : 0) | (mode & AESOCKET_WRITE ? EV_WRITE : 0); -#else - socket_op->flags = (mode & AESOCKET_READ ? EPOLLIN : 0) - | (mode & AESOCKET_WRITE ? EPOLLOUT : 0); -#endif assert(socket_op->flags && "Need to specify one of AESOCKET_READ|AESOCKET_WRITE"); *__ae_op_id = socket_op->op_id; -#ifdef __AESOP_LIBEV /* TODO: this is a temporary, dirty hack. If we believe that the * resource is being invoked from the same thread that is running the * event loop, then we don't have to worry about thread safety and we @@ -212,28 +120,6 @@ ae_define_post(triton_ret_t, triton_aesocket_ready, int fd, triton_mutex_unlock(&aesocket_mutex); ae_resource_request_poll(op->ctx, triton_aesocket_resource_id); } -#else - event.data.ptr = op; - event.events = socket_op->flags; - event.events |= EPOLLONESHOT; - - /* TODO: think about races and how to prevent them if any */ - /* TODO: this is a hack method to track which fds have been added to the set already, just for testing */ - assert(fd < MAX_FDS); - if(!known_fds[fd]) - { - ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event); - known_fds[fd] = 1; - } - else - { - ret = epoll_ctl(epfd, EPOLL_CTL_MOD, fd, &event); - } - if(ret < 0) - { - return(TRITON_ERR_EPOLL); - } -#endif return TRITON_SUCCESS; } @@ -241,7 +127,6 @@ ae_define_post(triton_ret_t, triton_aesocket_ready, int fd, static triton_ret_t triton_aesocket_poll( ae_context_t context) { -#ifdef __AESOP_LIBEV struct ae_op *op; struct aesocket_op *socket_op; struct ev_loop *eloop; @@ -279,9 +164,6 @@ static triton_ret_t triton_aesocket_poll( } triton_mutex_unlock(&aesocket_mutex); -#else - thread_fn(NULL); -#endif return TRITON_SUCCESS; } @@ -291,7 +173,6 @@ static triton_ret_t triton_aesocket_cancel( ae_context_t triton_ctx, ae_op_id_t op_id) { -#ifdef __AESOP_LIBEV int resource_id; struct ae_op *op; struct aesocket_op *socket_op; @@ -333,43 +214,14 @@ static triton_ret_t triton_aesocket_cancel( triton_mutex_unlock(&aesocket_mutex); /* already cancelled */ } -#else - /* TODO: implement cancel in epoll version */ - assert(0); -#endif - - return(TRITON_SUCCESS); -} - -#ifdef __AESOP_EPOLL -/* TODO: yet another dirty hack; I'm going to use this to reach into the - * context and replace the pipe fd that epoll is watching with my own fd - */ -static triton_ret_t triton_aesocket_register_context(ae_context_t context) -{ - int i; - - for(i=0; i<context->resource_count; i++) - { - if(context->poll_data[i].poll_context == triton_aesocket_poll) - break; - } - close(context->poll_data[i].pipe_fds[0]); - close(context->poll_data[i].pipe_fds[1]); - context->poll_data[i].pipe_fds[0] = epfd; - context->poll_data[i].pipe_fds[1] = 0; return(TRITON_SUCCESS); } -#endif struct ae_resource triton_aesocket_resource = { .resource_name = "aesocket", .poll_context = triton_aesocket_poll, .cancel = triton_aesocket_cancel, -#ifdef __AESOP_EPOLL - .register_context = triton_aesocket_register_context -#endif }; __attribute__ ((constructor)) @@ -390,13 +242,11 @@ triton_ret_t triton_aesocket_init( triton_ret_t tret; int ret; -#ifdef __AESOP_LIBEV event_loop_thread = pthread_self(); ae_ops_init(&posted_oplist); ae_ops_init(&cancelled_oplist); ae_ops_init(&inflight_oplist); -#endif tret = AE_OPCACHE_INIT(struct aesocket_op, op, @@ -406,24 +256,6 @@ triton_ret_t triton_aesocket_init( { return tret; } -#ifdef __AESOP_EPOLL - epfd = epoll_create(32); - if(epfd < 0) - { - ae_opcache_destroy(aesocket_opcache); - return(TRITON_ERR_EPOLL); - } -#if 0 - epoll_thread_running = 1; - ret = pthread_create(&epoll_thread, NULL, thread_fn, NULL); - if(ret < 0) - { - ae_opcache_destroy(aesocket_opcache); - close(epfd); - return(TRITON_ERR_EPOLL); - } -#endif -#endif return ae_resource_register(&triton_aesocket_resource, &triton_aesocket_resource_id); @@ -432,13 +264,6 @@ triton_ret_t triton_aesocket_init( void triton_aesocket_finalize( void) { -#ifdef __AESOP_EPOLL -#if 0 - epoll_thread_running = 0; - pthread_join(epoll_thread, NULL); -#endif - close(epfd); -#endif ae_resource_unregister(triton_aesocket_resource_id); ae_opcache_destroy(aesocket_opcache); } diff --git a/code/src/common/resources/timer/timer.c b/code/src/common/resources/timer/timer.c index d5cce84..76fc0d2 100644 --- a/code/src/common/resources/timer/timer.c +++ b/code/src/common/resources/timer/timer.c @@ -11,30 +11,22 @@ #include "src/aesop/opcache.h" #include "src/common/resources/timer/timer.h" #include "src/common/triton-init.h" -#ifdef __AESOP_LIBEV #include "src/common/libev/ev.h" -#endif /* NOTES: * - * This resource uses the POSIX timer interface to implement an aesop timer - * resource. The aesop callbacks are driven directly from the timer - * notfication function. + * This resource sets timers in the aesop libev event loop. + * + * TODO: There are some unresolved thread safety issues here. */ #define TIMER_DEFAULT_SIZE 1024 static ae_opcache_t timer_opcache = NULL; static int triton_timer_resource_id; -#ifdef __AESOP_LIBEV static ev_timer timer_watcher; static struct ev_loop* timer_loop = NULL; static void timer_cb(EV_P_ ev_timer *w, int revents); -#else -static timer_t timer_id; -static struct sigevent evp; -static void timer_notify(union sigval sv); -#endif struct timer_op { @@ -45,9 +37,6 @@ struct timer_op }; static triton_mutex_t timer_mutex = TRITON_MUTEX_INITIALIZER; static ae_ops_t timer_oplist; -#if 0 -static ae_ops_t cancel_oplist; -#endif ae_define_post(triton_ret_t, triton_timer, int millisecs) { @@ -57,9 +46,6 @@ ae_define_post(triton_ret_t, triton_timer, int millisecs) struct ae_op *op; struct ae_op *iter, *safe, *holder; struct timer_op *timer_op_iter; -#ifndef __AESOP_LIBEV - struct itimerspec tspec; -#endif if(!timer_opcache) { @@ -110,20 +96,11 @@ ae_define_post(triton_ret_t, triton_timer, int millisecs) if(holder == op) { /* new head of queue; arm a new timer or modify the existing one */ -#ifdef __AESOP_LIBEV if(timer_loop) ev_timer_stop(timer_loop, &timer_watcher); ev_timer_set(&timer_watcher, (((ev_tstamp)millisecs)/1000.0), 0); timer_loop = ae_resource_get_eloop(op->ctx); ev_timer_start(timer_loop, &timer_watcher); -#else - memset(&tspec, 0, sizeof(tspec)); - tspec.it_value.tv_sec = (int)(millisecs/1000); - tspec.it_value.tv_nsec = (millisecs % 1000) * 1e6; - ret = timer_settime(timer_id, 0, &tspec, NULL); - /* TODO: error handling (cancel all remaining timers?) */ - assert(ret == 0); -#endif } *__ae_op_id = top->op_id; @@ -133,40 +110,11 @@ ae_define_post(triton_ret_t, triton_timer, int millisecs) return TRITON_SUCCESS; } -static triton_ret_t triton_timer_poll(ae_context_t context) -{ - struct ae_op *op; - struct timer_op *top; - - /* there is nothing for a timer poll to do */ -#if 0 - /* harvest any timers that have been cancelled */ - triton_mutex_lock(&timer_mutex); - while((op = ae_ops_dequeue(&cancel_oplist))) - { - triton_mutex_unlock(&timer_mutex); - - top = ae_op_entry(op, struct timer_op, op); - assert(top->tret == TRITON_ERR_CANCELED); - ae_opcache_complete_op(timer_opcache, op, triton_ret_t, top->tret); - triton_mutex_lock(&timer_mutex); - } - triton_mutex_unlock(&timer_mutex); -#endif - - return TRITON_SUCCESS; -} - static triton_ret_t triton_timer_cancel(ae_context_t triton_ctx, ae_op_id_t op_id) { /* TODO: do we have to check for races here (trying to cancel an ae_op * that no longer exists) , or does aesop do that for us? */ - -#ifndef __AESOP_LIBEV - struct itimerspec tspec; - struct itimerspec old_tspec; -#endif int resource_id; struct ae_op *op; struct timer_op *top; @@ -203,18 +151,6 @@ static triton_ret_t triton_timer_cancel(ae_context_t triton_ctx, ae_op_id_t op_i ctx = op->ctx; triton_mutex_unlock(&timer_mutex); ae_opcache_complete_op(timer_opcache, op, triton_ret_t, TRITON_ERR_CANCELED); - /* deprecated: this logic handles cancelled timers by putting them on a - * queue to be harvested on the next poll call. - */ -#if 0 - /* move to a special queue of cancelled timers */ - ctx = op->ctx; - ae_ops_enqueue(op, &cancel_oplist); - /* request a poll for aesop to harvest the cancelled timer */ - ae_resource_request_poll(ctx, triton_timer_resource_id); - - triton_mutex_unlock(&timer_mutex); -#endif return TRITON_SUCCESS; } @@ -222,7 +158,6 @@ static triton_ret_t triton_timer_cancel(ae_context_t triton_ctx, ae_op_id_t op_i struct ae_resource triton_timer_resource = { .resource_name = "timer", - .poll_context = triton_timer_poll, .cancel = triton_timer_cancel }; @@ -238,26 +173,9 @@ triton_ret_t triton_timer_init(void) triton_ret_t tret; int ret; -#ifdef __AESOP_LIBEV ev_init(&timer_watcher, timer_cb); -#else - memset(&evp, 0, sizeof(evp)); - evp.sigev_notify = SIGEV_THREAD; - evp.sigev_value.sival_ptr = NULL; - evp.sigev_notify_function = timer_notify; - - ret = timer_create(CLOCK_REALTIME, &evp, &timer_id); - if(ret < 0) - { - triton_err(triton_log_default, "Error: failed to create timer."); - return(TRITON_ERR_NOMEM); - } -#endif ae_ops_init(&timer_oplist); -#if 0 - ae_ops_init(&cancel_oplist); -#endif tret = AE_OPCACHE_INIT(struct timer_op, op, TIMER_DEFAULT_SIZE, &timer_opcache); if(tret != TRITON_SUCCESS) @@ -272,18 +190,10 @@ void triton_timer_finalize(void) { ae_resource_unregister(triton_timer_resource_id); -#ifndef __AESOP_LIBEV - timer_delete(timer_id); -#endif - ae_opcache_destroy(timer_opcache); } -#ifdef __AESOP_LIBEV static void timer_cb(EV_P_ ev_timer *w, int revents) -#else -static void timer_notify(union sigval sv) -#endif { struct ae_op *gop; struct timer_op *top; @@ -292,11 +202,7 @@ static void timer_notify(union sigval sv) int did_something = 0; ae_context_t ctx; int ret; -#ifdef __AESOP_LIBEV ev_tstamp tstamp; -#else - struct itimerspec tspec; -#endif triton_mutex_lock(&timer_mutex); @@ -335,21 +241,12 @@ static void timer_notify(union sigval sv) diff.tv_usec = 1; } -#ifdef __AESOP_LIBEV tstamp = (ev_tstamp)diff.tv_sec + (ev_tstamp)diff.tv_usec / 1000000.0; if(timer_loop) ev_timer_stop(timer_loop, &timer_watcher); ev_timer_set(&timer_watcher, tstamp, 0); timer_loop = ae_resource_get_eloop(gop->ctx); ev_timer_start(timer_loop, &timer_watcher); -#else - memset(&tspec, 0, sizeof(tspec)); - tspec.it_value.tv_sec = diff.tv_sec; - tspec.it_value.tv_nsec = diff.tv_usec * 1e3; - ret = timer_settime(timer_id, 0, &tspec, NULL); - /* TODO: error handling (cancel all remaining timers?) */ - assert(ret == 0); -#endif } triton_mutex_unlock(&timer_mutex); hooks/post-receive -- Triton Repository