comparison src/event/ngx_event.c @ 303:00c5660d2707

nginx-0.0.3-2004-04-01-20:20:53 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 01 Apr 2004 16:20:53 +0000
parents 744965ec6275
children bcbe876f4262
comparison
equal deleted inserted replaced
302:1526e7686b20 303:00c5660d2707
26 26
27 #if (HAVE_AIO) 27 #if (HAVE_AIO)
28 #include <ngx_aio_module.h> 28 #include <ngx_aio_module.h>
29 #endif 29 #endif
30 30
31 static int ngx_event_init(ngx_cycle_t *cycle); 31 static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle);
32 static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle);
32 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 33 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
33 34
34 static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, 35 static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd,
35 void *conf); 36 void *conf);
36 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 37 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
37 38
38 static void *ngx_event_create_conf(ngx_cycle_t *cycle); 39 static void *ngx_event_create_conf(ngx_cycle_t *cycle);
39 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); 40 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf);
40 41
41 42
42 int ngx_event_flags; 43 static ngx_uint_t ngx_event_max_module;
43 ngx_event_actions_t ngx_event_actions; 44
44 45 ngx_uint_t ngx_event_flags;
45 46 ngx_event_actions_t ngx_event_actions;
46 static int ngx_event_max_module; 47
48
49 ngx_atomic_t *ngx_accept_mutex_ptr;
50 ngx_atomic_t *ngx_accept_mutex;
51 ngx_uint_t ngx_accept_mutex_held;
52
47 53
48 ngx_thread_volatile ngx_event_t *ngx_posted_events; 54 ngx_thread_volatile ngx_event_t *ngx_posted_events;
49 #if (NGX_THREADS) 55 #if (NGX_THREADS)
50 ngx_mutex_t *ngx_posted_events_mutex; 56 ngx_mutex_t *ngx_posted_events_mutex;
51 #endif 57 #endif
99 ngx_conf_set_flag_slot, 105 ngx_conf_set_flag_slot,
100 0, 106 0,
101 offsetof(ngx_event_conf_t, multi_accept), 107 offsetof(ngx_event_conf_t, multi_accept),
102 NULL }, 108 NULL },
103 109
110 { ngx_string("accept_mutex"),
111 NGX_EVENT_CONF|NGX_CONF_TAKE1,
112 ngx_conf_set_flag_slot,
113 0,
114 offsetof(ngx_event_conf_t, accept_mutex),
115 NULL },
116
104 ngx_null_command 117 ngx_null_command
105 }; 118 };
106 119
107 120
108 ngx_event_module_t ngx_event_core_module_ctx = { 121 ngx_event_module_t ngx_event_core_module_ctx = {
117 ngx_module_t ngx_event_core_module = { 130 ngx_module_t ngx_event_core_module = {
118 NGX_MODULE, 131 NGX_MODULE,
119 &ngx_event_core_module_ctx, /* module context */ 132 &ngx_event_core_module_ctx, /* module context */
120 ngx_event_core_commands, /* module directives */ 133 ngx_event_core_commands, /* module directives */
121 NGX_EVENT_MODULE, /* module type */ 134 NGX_EVENT_MODULE, /* module type */
122 NULL, /* init module */ 135 ngx_event_module_init, /* init module */
123 ngx_event_init /* init child */ 136 ngx_event_process_init /* init process */
124 }; 137 };
125 138
126 139
127 static int ngx_event_init(ngx_cycle_t *cycle) 140 static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
141 {
142 ngx_core_conf_t *ccf;
143 ngx_event_conf_t *ecf;
144
145 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
146
147 if (ccf->master == 0) {
148 return NGX_OK;
149 }
150
151 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
152
153 if (ecf->accept_mutex == 0) {
154 return NGX_OK;
155 }
156
157 ngx_accept_mutex_ptr = mmap(NULL, sizeof(ngx_atomic_t),
158 PROT_READ|PROT_WRITE,
159 MAP_ANON|MAP_SHARED, -1, 0);
160
161 if (ngx_accept_mutex_ptr == NULL) {
162 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
163 "mmap(MAP_ANON|MAP_SHARED) failed");
164 return NGX_ERROR;
165 }
166
167 return NGX_OK;
168 }
169
170
171 static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
128 { 172 {
129 ngx_uint_t m, i; 173 ngx_uint_t m, i;
130 ngx_socket_t fd; 174 ngx_socket_t fd;
131 ngx_event_t *rev, *wev; 175 ngx_event_t *rev, *wev;
132 ngx_listening_t *s; 176 ngx_listening_t *s;
133 ngx_connection_t *c; 177 ngx_connection_t *c;
178 ngx_core_conf_t *ccf;
134 ngx_event_conf_t *ecf; 179 ngx_event_conf_t *ecf;
135 ngx_event_module_t *module; 180 ngx_event_module_t *module;
136 #if (WIN32) 181 #if (WIN32)
137 ngx_iocp_conf_t *iocpcf; 182 ngx_iocp_conf_t *iocpcf;
138 #endif 183 #endif
139 184
185
186 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
187
188 if (ccf->worker_processes > 1 && ngx_accept_mutex_ptr) {
189 ngx_accept_mutex = ngx_accept_mutex_ptr;
190 ngx_accept_mutex_held = 1;
191 }
140 192
141 #if (NGX_THREADS) 193 #if (NGX_THREADS)
142 if (!(ngx_posted_events_mutex = ngx_mutex_init(cycle->log, 0))) { 194 if (!(ngx_posted_events_mutex = ngx_mutex_init(cycle->log, 0))) {
143 return NGX_ERROR; 195 return NGX_ERROR;
144 } 196 }
468 NGX_CONF_ERROR); 520 NGX_CONF_ERROR);
469 521
470 ecf->connections = NGX_CONF_UNSET; 522 ecf->connections = NGX_CONF_UNSET;
471 ecf->use = NGX_CONF_UNSET; 523 ecf->use = NGX_CONF_UNSET;
472 ecf->multi_accept = NGX_CONF_UNSET; 524 ecf->multi_accept = NGX_CONF_UNSET;
525 ecf->accept_mutex = NGX_CONF_UNSET;
473 ecf->name = (void *) NGX_CONF_UNSET; 526 ecf->name = (void *) NGX_CONF_UNSET;
474 527
475 return ecf; 528 return ecf;
476 } 529 }
477 530
540 #endif 593 #endif
541 594
542 cycle->connection_n = ecf->connections; 595 cycle->connection_n = ecf->connections;
543 596
544 ngx_conf_init_value(ecf->multi_accept, 0); 597 ngx_conf_init_value(ecf->multi_accept, 0);
598 ngx_conf_init_value(ecf->accept_mutex, 1);
545 599
546 return NGX_CONF_OK; 600 return NGX_CONF_OK;
547 } 601 }