From: Brian Pane Date: Sun, 13 Nov 2005 02:27:44 +0000 (+0000) Subject: Minor refactoring: move the creation of the pollset and associated X-Git-Tag: 2.3.0~2794 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=596e8e2d9d24bae29e3af30f0e3fc2e1bb4f54cd;p=apache Minor refactoring: move the creation of the pollset and associated data structures outside of the listener thread function. The point of this is to facilitate future experiments with different concurrency models like Leader/Followers as potential alternatives to the current Reactor design. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@332879 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/mpm/experimental/event/event.c b/server/mpm/experimental/event/event.c index c5393c1c28..eb5ab62aed 100644 --- a/server/mpm/experimental/event/event.c +++ b/server/mpm/experimental/event/event.c @@ -765,6 +765,51 @@ static void dummy_signal_handler(int sig) */ } +static apr_status_t init_pollset(apr_pool_t *p) +{ + apr_status_t rv; + ap_listen_rec *lr; + listener_poll_type *pt; + + rv = apr_thread_mutex_create(&timeout_mutex, APR_THREAD_MUTEX_DEFAULT, p); + if (rv != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, + "creation of the timeout mutex failed."); + return rv; + } + + APR_RING_INIT(&timeout_head, conn_state_t, timeout_list); + APR_RING_INIT(&keepalive_timeout_head, conn_state_t, timeout_list); + + /* Create the main pollset */ + rv = apr_pollset_create(&event_pollset, + ap_threads_per_child, + p, APR_POLLSET_THREADSAFE | APR_POLLSET_NOCOPY); + if (rv != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, + "apr_pollset_create with Thread Safety failed."); + return rv; + } + + for (lr = ap_listeners; lr != NULL; lr = lr->next) { + apr_pollfd_t *pfd = apr_palloc(p, sizeof(*pfd)); + pt = apr_pcalloc(p, sizeof(*pt)); + pfd->desc_type = APR_POLL_SOCKET; + pfd->desc.s = lr->sd; + pfd->reqevents = APR_POLLIN; + + pt->type = PT_ACCEPT; + pt->baton = lr; + + pfd->client_data = pt; + + apr_socket_opt_set(pfd->desc.s, APR_SO_NONBLOCK, 1); + apr_pollset_add(event_pollset, pfd); + } + + return APR_SUCCESS; +} + static apr_status_t push2worker(const apr_pollfd_t * pfd, apr_pollset_t * pollset) { @@ -875,47 +920,15 @@ static void *listener_thread(apr_thread_t * thd, void *dummy) */ #define TIMEOUT_FUDGE_FACTOR 100000 - rc = apr_thread_mutex_create(&timeout_mutex, APR_THREAD_MUTEX_DEFAULT, - tpool); - if (rc != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_ERR, rc, ap_server_conf, - "creation of the timeout mutex failed. Attempting to " - "shutdown process gracefully"); - signal_threads(ST_GRACEFUL); - return NULL; - } - - APR_RING_INIT(&timeout_head, conn_state_t, timeout_list); - APR_RING_INIT(&keepalive_timeout_head, conn_state_t, timeout_list); - - /* Create the main pollset */ - rc = apr_pollset_create(&event_pollset, - ap_threads_per_child, - tpool, APR_POLLSET_THREADSAFE | APR_POLLSET_NOCOPY); + rc = init_pollset(tpool); if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rc, ap_server_conf, - "apr_pollset_create with Thread Safety failed. " - "Attempting to shutdown process gracefully"); + "failed to initialize pollset, " + "attempting to shutdown process gracefully"); signal_threads(ST_GRACEFUL); return NULL; } - for (lr = ap_listeners; lr != NULL; lr = lr->next) { - apr_pollfd_t *pfd = apr_palloc(tpool, sizeof(*pfd)); - pt = apr_pcalloc(tpool, sizeof(*pt)); - pfd->desc_type = APR_POLL_SOCKET; - pfd->desc.s = lr->sd; - pfd->reqevents = APR_POLLIN; - - pt->type = PT_ACCEPT; - pt->baton = lr; - - pfd->client_data = pt; - - apr_socket_opt_set(pfd->desc.s, APR_SO_NONBLOCK, 1); - apr_pollset_add(event_pollset, pfd); - } - /* Unblock the signal used to wake this thread up, and set a handler for * it. */