]> git.kaiwu.me - nginx.git/commitdiff
nginx-0.0.3-2004-03-31-00:31:58 import
authorIgor Sysoev <igor@sysoev.ru>
Tue, 30 Mar 2004 20:31:58 +0000 (20:31 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Tue, 30 Mar 2004 20:31:58 +0000 (20:31 +0000)
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

index a19695ccf48327a0b498759fbedae1abe310a2ae..8dc6102405f9d61aff6139f2315275db129e2e7f 100644 (file)
@@ -36,18 +36,18 @@ static ngx_command_t  ngx_core_commands[] = {
       offsetof(ngx_core_conf_t, master),
       NULL },
 
-    { ngx_string("pid"),
+    { ngx_string("worker_processes"),
       NGX_MAIN_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_core_str_slot,
+      ngx_conf_set_core_num_slot,
       0,
-      offsetof(ngx_core_conf_t, pid),
+      offsetof(ngx_core_conf_t, worker_processes),
       NULL },
 
-    { ngx_string("worker_reopen"),
+    { ngx_string("pid"),
       NGX_MAIN_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_core_flag_slot,
+      ngx_conf_set_core_str_slot,
       0,
-      offsetof(ngx_core_conf_t, worker_reopen),
+      offsetof(ngx_core_conf_t, pid),
       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(ngx_cycle_t *cycle)
      */
     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;
 
index 31bf94c458de212897236848164691a292ffa110..b95e4cc461f92aaa37bcdd6b3e3805b4514e9ea2 100644 (file)
@@ -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_inc(ngx_atomic_t *value)
 {
     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_dec(ngx_atomic_t *value)
 {
     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;
 }
index 63918673c66341ac8f18ef6e931773f3e08eaa85..8f409eae58d50747c9f944c8e89d2ede3f653a4d 100644 (file)
@@ -571,6 +571,13 @@ char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
 }
 
 
+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)
 {
index ee90855e7c48719a610e69396304e14153ff7a86..ed73803a9483adf8986f2ceb4afc633b51174459 100644 (file)
@@ -256,6 +256,8 @@ char *ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *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);
 
index 2ea229ea423c0691f917586e10838d9e4d4d54d3..df1f3903326cbaab883955cb0c7d51b09a7dd776 100644 (file)
@@ -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;
index 586f560dca638deda2342eb468db5319af904b6b..a433e1d903b1f6941c36bc8a14cdb0c807be9849 100644 (file)
@@ -193,7 +193,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
      *             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) {
index 48b7ba4982bc954f72e6c64762016f7b31e36b38..1f449e2394c196544cac8de7fdbda58b760379df 100644 (file)
@@ -1405,7 +1405,10 @@ static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
     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);
index e4d95ada9cb47bb9580fa4a40cc12c37201b16c6..cc3d8a4c42d2e9773d2333945b0c05009b8e792c 100644 (file)
@@ -68,9 +68,14 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
     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_t *cycle, ngx_master_ctx_t *ctx)
             }
         }
 
-        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_t *cycle, ngx_master_ctx_t *ctx)
 
                     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_t *cycle, ngx_master_ctx_t *ctx)
 
                         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);
                     }
                 }