diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2004-04-01 16:20:53 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2004-04-01 16:20:53 +0000 |
| commit | dbb27765706e2d2f35b0af57c317b58d2d9d6ec9 (patch) | |
| tree | 69760523cc77e8244f0f1d5c3c0247544a1179b9 /src/event | |
| parent | 205dc145c5d22613826927d6ae8ccd3a69d0e907 (diff) | |
| download | nginx-dbb27765706e2d2f35b0af57c317b58d2d9d6ec9.tar.gz nginx-dbb27765706e2d2f35b0af57c317b58d2d9d6ec9.tar.bz2 | |
nginx-0.0.3-2004-04-01-20:20:53 import
Diffstat (limited to 'src/event')
| -rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 2 | ||||
| -rw-r--r-- | src/event/ngx_event.c | 68 | ||||
| -rw-r--r-- | src/event/ngx_event.h | 9 | ||||
| -rw-r--r-- | src/event/ngx_event_accept.c | 5 | ||||
| -rw-r--r-- | src/event/ngx_event_timer.h | 19 |
5 files changed, 83 insertions, 20 deletions
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index 8d37d0187..9f0cd1857 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -375,7 +375,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) return NGX_ERROR; } -#if 0 +#if 1 if (ngx_accept_mutex_held == 0 && timer == 0) { /* STUB */ timer = 500; } diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index 5678c8489..b50b8739c 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -28,7 +28,8 @@ extern ngx_event_module_t ngx_epoll_module_ctx; #include <ngx_aio_module.h> #endif -static int ngx_event_init(ngx_cycle_t *cycle); +static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle); +static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle); static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, @@ -39,11 +40,16 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle); static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); -int ngx_event_flags; -ngx_event_actions_t ngx_event_actions; +static ngx_uint_t ngx_event_max_module; +ngx_uint_t ngx_event_flags; +ngx_event_actions_t ngx_event_actions; + + +ngx_atomic_t *ngx_accept_mutex_ptr; +ngx_atomic_t *ngx_accept_mutex; +ngx_uint_t ngx_accept_mutex_held; -static int ngx_event_max_module; ngx_thread_volatile ngx_event_t *ngx_posted_events; #if (NGX_THREADS) @@ -101,6 +107,13 @@ static ngx_command_t ngx_event_core_commands[] = { offsetof(ngx_event_conf_t, multi_accept), NULL }, + { ngx_string("accept_mutex"), + NGX_EVENT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + 0, + offsetof(ngx_event_conf_t, accept_mutex), + NULL }, + ngx_null_command }; @@ -119,18 +132,50 @@ ngx_module_t ngx_event_core_module = { &ngx_event_core_module_ctx, /* module context */ ngx_event_core_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ - NULL, /* init module */ - ngx_event_init /* init child */ + ngx_event_module_init, /* init module */ + ngx_event_process_init /* init process */ }; -static int ngx_event_init(ngx_cycle_t *cycle) +static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) +{ + ngx_core_conf_t *ccf; + ngx_event_conf_t *ecf; + + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + + if (ccf->master == 0) { + return NGX_OK; + } + + ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); + + if (ecf->accept_mutex == 0) { + return NGX_OK; + } + + ngx_accept_mutex_ptr = mmap(NULL, sizeof(ngx_atomic_t), + PROT_READ|PROT_WRITE, + MAP_ANON|MAP_SHARED, -1, 0); + + if (ngx_accept_mutex_ptr == NULL) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + "mmap(MAP_ANON|MAP_SHARED) failed"); + return NGX_ERROR; + } + + return NGX_OK; +} + + +static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle) { ngx_uint_t m, i; ngx_socket_t fd; ngx_event_t *rev, *wev; ngx_listening_t *s; ngx_connection_t *c; + ngx_core_conf_t *ccf; ngx_event_conf_t *ecf; ngx_event_module_t *module; #if (WIN32) @@ -138,6 +183,13 @@ static int ngx_event_init(ngx_cycle_t *cycle) #endif + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + + if (ccf->worker_processes > 1 && ngx_accept_mutex_ptr) { + ngx_accept_mutex = ngx_accept_mutex_ptr; + ngx_accept_mutex_held = 1; + } + #if (NGX_THREADS) if (!(ngx_posted_events_mutex = ngx_mutex_init(cycle->log, 0))) { return NGX_ERROR; @@ -470,6 +522,7 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle) ecf->connections = NGX_CONF_UNSET; ecf->use = NGX_CONF_UNSET; ecf->multi_accept = NGX_CONF_UNSET; + ecf->accept_mutex = NGX_CONF_UNSET; ecf->name = (void *) NGX_CONF_UNSET; return ecf; @@ -542,6 +595,7 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) cycle->connection_n = ecf->connections; ngx_conf_init_value(ecf->multi_accept, 0); + ngx_conf_init_value(ecf->accept_mutex, 1); return NGX_CONF_OK; } diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 69a08cd8a..7fa1a9365 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -374,9 +374,12 @@ extern ngx_event_actions_t ngx_event_actions; typedef struct { - int connections; - int use; + ngx_int_t connections; + ngx_int_t use; + ngx_flag_t multi_accept; + ngx_flag_t accept_mutex; + u_char *name; } ngx_event_conf_t; @@ -407,7 +410,7 @@ extern ngx_uint_t ngx_accept_mutex_held; } -extern int ngx_event_flags; +extern ngx_uint_t ngx_event_flags; extern ngx_module_t ngx_events_module; extern ngx_module_t ngx_event_core_module; diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index d1942d581..41794bea9 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -14,11 +14,6 @@ typedef struct { static size_t ngx_accept_log_error(void *data, char *buf, size_t len); -ngx_atomic_t *ngx_accept_mutex_ptr; -ngx_atomic_t *ngx_accept_mutex; -ngx_uint_t ngx_accept_mutex_held; - - void ngx_event_accept(ngx_event_t *ev) { ngx_uint_t instance, rinstance, winstance, accepted; diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h index 21f261f88..0eae57043 100644 --- a/src/event/ngx_event_timer.h +++ b/src/event/ngx_event_timer.h @@ -67,17 +67,28 @@ ngx_inline static void ngx_event_del_timer(ngx_event_t *ev) ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) { - if (ev->timer_set) { - ngx_del_timer(ev); - } + ngx_int_t key; - ev->rbtree_key = (ngx_int_t) + key = (ngx_int_t) (ngx_elapsed_msec / NGX_TIMER_RESOLUTION * NGX_TIMER_RESOLUTION + timer) / NGX_TIMER_RESOLUTION; #if 0 (ngx_elapsed_msec + timer) / NGX_TIMER_RESOLUTION; #endif + if (ev->timer_set) { + if (key - ev->rbtree_key < 50) { + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, + "event timer: %d, old: %d, new: %d", + ngx_event_ident(ev->data), ev->rbtree_key, key); + return; + } + + ngx_del_timer(ev); + } + + ev->rbtree_key = key; + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, "event timer add: %d: %d", ngx_event_ident(ev->data), ev->rbtree_key); |
