changeset 300:502b03d9d2a3

nginx-0.0.3-2004-03-31-00:31:58 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 30 Mar 2004 20:31:58 +0000
parents 46b7eeb8a116
children 744965ec6275
files src/core/nginx.c src/core/ngx_atomic.h src/core/ngx_conf_file.c src/core/ngx_conf_file.h src/core/ngx_cycle.h src/event/ngx_event_connect.c src/http/ngx_http_core_module.c src/os/unix/ngx_process_cycle.c
diffstat 8 files changed, 44 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -36,6 +36,13 @@ static ngx_command_t  ngx_core_commands[
       offsetof(ngx_core_conf_t, master),
       NULL },
 
+    { ngx_string("worker_processes"),
+      NGX_MAIN_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_core_num_slot,
+      0,
+      offsetof(ngx_core_conf_t, worker_processes),
+      NULL },
+
     { ngx_string("pid"),
       NGX_MAIN_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_core_str_slot,
@@ -43,13 +50,6 @@ static ngx_command_t  ngx_core_commands[
       offsetof(ngx_core_conf_t, pid),
       NULL },
 
-    { ngx_string("worker_reopen"),
-      NGX_MAIN_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_core_flag_slot,
-      0,
-      offsetof(ngx_core_conf_t, worker_reopen),
-      NULL },
-
       ngx_null_command
 };
 
@@ -174,6 +174,10 @@ int main(int argc, char *const *argv)
         }
     }
 
+    if (ccf->worker_processes == NGX_CONF_UNSET) {
+        ccf->worker_processes = 1;
+    }
+
     if (ccf->pid.len == 0) {
         ccf->pid.len = sizeof(NGINX_PID) - 1;
         ccf->pid.data = NGINX_PID;
@@ -361,7 +365,7 @@ static ngx_int_t ngx_core_module_init(ng
      */
     ccf->daemon = NGX_CONF_UNSET;
     ccf->master = NGX_CONF_UNSET;
-    ccf->worker_reopen = NGX_CONF_UNSET;
+    ccf->worker_processes = NGX_CONF_UNSET;
     ccf->user = (ngx_uid_t) NGX_CONF_UNSET;
     ccf->group = (ngx_gid_t) NGX_CONF_UNSET;
 
--- a/src/core/ngx_atomic.h
+++ b/src/core/ngx_atomic.h
@@ -11,7 +11,7 @@
 typedef volatile uint32_t  ngx_atomic_t;
 
 #if (NGX_SMP)
-#define NGX_SMP_LOCK  "lock"
+#define NGX_SMP_LOCK  "lock;"
 #else
 #define NGX_SMP_LOCK
 #endif
@@ -21,14 +21,12 @@ static ngx_inline uint32_t ngx_atomic_in
 {
     uint32_t  old;
 
-    old = 1;
-
     __asm__ volatile (
 
         NGX_SMP_LOCK
-    "   xaddl  %0, %1;   "
+    "   xaddl  %0, %2;   "
 
-    : "+q" (old) : "m" (*value));
+    : "=q" (old) : "0" (1), "m" (*value));
 
     return old;
 }
@@ -38,14 +36,12 @@ static ngx_inline uint32_t ngx_atomic_de
 {
     uint32_t  old;
 
-    old = (uint32_t) -1;
-
     __asm__ volatile (
 
         NGX_SMP_LOCK
     "   xaddl  %0, %1;   "
 
-    : "+q" (old) : "m" (*value));
+    : "=q" (old) : "0" (-1), "m" (*value));
 
     return old;
 }
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -571,6 +571,13 @@ char *ngx_conf_set_core_flag_slot(ngx_co
 }
 
 
+char *ngx_conf_set_core_num_slot(ngx_conf_t *cf, ngx_command_t *cmd,
+                                 void *conf)
+{
+    return ngx_conf_set_num_slot(cf, cmd, *(void **)conf);
+}
+
+
 char *ngx_conf_set_core_str_slot(ngx_conf_t *cf, ngx_command_t *cmd,
                                  void *conf)
 {
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -256,6 +256,8 @@ char *ngx_conf_set_bitmask_slot(ngx_conf
 
 char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
                                   void *conf);
+char *ngx_conf_set_core_num_slot(ngx_conf_t *cf, ngx_command_t *cmd,
+                                 void *conf);
 char *ngx_conf_set_core_str_slot(ngx_conf_t *cf, ngx_command_t *cmd,
                                  void *conf);
 
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -28,9 +28,12 @@ struct ngx_cycle_s {
 typedef struct {
      ngx_flag_t  daemon;
      ngx_flag_t  master;
-     ngx_flag_t  worker_reopen;
+
+     ngx_int_t   worker_processes;
+
      ngx_uid_t   user;
      ngx_gid_t   group;
+
      ngx_str_t   pid;
      ngx_str_t   newpid;
 } ngx_core_conf_t;
--- a/src/event/ngx_event_connect.c
+++ b/src/event/ngx_event_connect.c
@@ -193,7 +193,7 @@ int ngx_event_connect_peer(ngx_peer_conn
      *             or protection by critical section or mutex
      */
 
-    c->number = ngx_connection_counter++;
+    c->number = ngx_atomic_inc(&ngx_connection_counter);
 
     if (ngx_add_conn) {
         if (ngx_add_conn(c) == NGX_ERROR) {
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1405,7 +1405,10 @@ static char *ngx_set_root(ngx_conf_t *cf
     alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;
 
     if (lcf->root.data) {
-        if (lcf->alias == alias) {
+
+        /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */
+
+        if ((ngx_uint_t) lcf->alias == alias) {
             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                "\"%s\" directive is duplicate",
                                cmd->name.data);
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -68,9 +68,14 @@ void ngx_master_process_cycle(ngx_cycle_
     for ( ;; ) {
         ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle");
 
+        ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
+                                               ngx_core_module);
+
         if (ngx_process == NGX_PROCESS_MASTER) {
-            ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
-                              "worker process", NGX_PROCESS_RESPAWN);
+            for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) {
+                ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
+                                  "worker process", NGX_PROCESS_RESPAWN);
+            }
 
             /*
              * we have to limit the maximum life time of the worker processes
@@ -103,8 +108,6 @@ void ngx_master_process_cycle(ngx_cycle_
             }
         }
 
-        ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
-                                               ngx_core_module);
 
         /* a cycle with the same configuration because a new one is invalid */
 
@@ -253,16 +256,8 @@ void ngx_master_process_cycle(ngx_cycle_
 
                     if (ngx_reopen) {
                         if (ngx_process == NGX_PROCESS_MASTER) {
-                            if (ccf->worker_reopen != 0) {
-                                signo = ngx_signal_value(NGX_REOPEN_SIGNAL);
-                                ngx_reopen = 0;
-
-                            } else if (ngx_noaccept) {
-                                ngx_reopen = 0;
-
-                            } else {
-                                signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL);
-                            }
+                            signo = ngx_signal_value(NGX_REOPEN_SIGNAL);
+                            ngx_reopen = 0;
 
                         } else { /* NGX_PROCESS_SINGLE */
                             ngx_reopen = 0;
@@ -270,8 +265,7 @@ void ngx_master_process_cycle(ngx_cycle_
 
                         ngx_log_error(NGX_LOG_INFO, cycle->log, 0,
                                       "reopening logs");
-                        ngx_reopen_files(cycle,
-                             ccf->worker_reopen != 0 ? ccf->user : (uid_t) -1);
+                        ngx_reopen_files(cycle, ccf->user);
                     }
                 }