diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-02-29 21:03:02 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-02-29 21:03:02 +0000 |
commit | d94049b6320504f3213adfaad939493676e83a3a (patch) | |
tree | 7a25b794030cbee22cca6e2bf27aa3569f915d2c /src/os/unix | |
parent | 898446c8bacb5b0e1c223dfec4643ebee8d07f8e (diff) | |
download | nginx-d94049b6320504f3213adfaad939493676e83a3a.tar.gz nginx-d94049b6320504f3213adfaad939493676e83a3a.zip |
nginx-0.0.2-2004-03-01-00:03:02 import
Diffstat (limited to 'src/os/unix')
-rw-r--r-- | src/os/unix/ngx_freebsd_rfork_thread.c | 82 | ||||
-rw-r--r-- | src/os/unix/ngx_freebsd_sendfile_chain.c | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_linux_sendfile_chain.c | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_process.c | 8 | ||||
-rw-r--r-- | src/os/unix/ngx_solaris_sendfilev_chain.c | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_thread.h | 45 |
6 files changed, 103 insertions, 47 deletions
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c index dd18168a2..e100b93c6 100644 --- a/src/os/unix/ngx_freebsd_rfork_thread.c +++ b/src/os/unix/ngx_freebsd_rfork_thread.c @@ -1,4 +1,9 @@ +/* + * Copyright (C) 2002-2004 Igor Sysoev, http://sysoev.ru/en/ + */ + + #include <ngx_config.h> #include <ngx_core.h> @@ -21,15 +26,12 @@ */ -ngx_int_t ngx_threaded; +ngx_int_t ngx_threaded; +char *ngx_freebsd_kern_usrstack; +size_t ngx_thread_stack_size; -static inline int ngx_gettid(); - -static char *usrstack; static size_t rz_size = /* STUB: PAGE_SIZE */ 4096; - -static size_t stack_size; static size_t usable_stack_size; static char *last_stack; @@ -54,12 +56,12 @@ int *__error() /* - * __isthreaded enables spinlock() in some libc functions, i.e. in malloc() + * __isthreaded enables the spinlocks in some libc functions, i.e. in malloc() * and some other places. Nevertheless we protect our malloc()/free() calls * by own mutex that is more efficient than the spinlock. * - * We define own _spinlock() because a weak referenced _spinlock() stub in - * src/lib/libc/gen/_spinlock_stub.c does nothing. + * _spinlock() is a weak referenced stub in src/lib/libc/gen/_spinlock_stub.c + * that does nothing. */ extern int __isthreaded; @@ -69,6 +71,7 @@ void _spinlock(ngx_atomic_t *lock) ngx_int_t tries; tries = 0; + for ( ;; ) { if (*lock) { @@ -88,6 +91,24 @@ void _spinlock(ngx_atomic_t *lock) } +/* + * Before FreeBSD 5.1 _spinunlock() is a simple #define in + * src/lib/libc/include/spinlock.h that zeroes lock. + * + * Since FreeBSD 5.1 _spinunlock() is a weak referenced stub in + * src/lib/libc/gen/_spinlock_stub.c that does nothing. + */ + +#ifndef _spinunlock + +void _spinunlock(ngx_atomic_t *lock) +{ + *lock = 0; +} + +#endif + + int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg, ngx_log_t *log) { @@ -100,7 +121,7 @@ int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg, return NGX_ERROR; } - last_stack -= stack_size; + last_stack -= ngx_thread_stack_size; stack = mmap(last_stack, usable_stack_size, PROT_READ|PROT_WRITE, MAP_STACK, -1, 0); @@ -139,7 +160,8 @@ int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg, } else { *tid = id; - nthreads = (usrstack - stack_top) / stack_size; + nthreads = (ngx_freebsd_kern_usrstack - stack_top) + / ngx_thread_stack_size; tids[nthreads] = id; ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %d", id); @@ -156,19 +178,21 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) max_threads = n; - len = sizeof(usrstack); - if (sysctlbyname("kern.usrstack", &usrstack, &len, NULL, 0) == -1) { + len = sizeof(ngx_freebsd_kern_usrstack); + if (sysctlbyname("kern.usrstack", &ngx_freebsd_kern_usrstack, &len, + NULL, 0) == -1) + { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "sysctlbyname(kern.usrstack) failed"); return NGX_ERROR; } /* the main thread stack red zone */ - red_zone = usrstack - (size + rz_size); + red_zone = ngx_freebsd_kern_usrstack - (size + rz_size); ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, "usrstack: " PTR_FMT " red zone: " PTR_FMT, - usrstack, red_zone); + ngx_freebsd_kern_usrstack, red_zone); zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0); if (zone == MAP_FAILED) { @@ -201,7 +225,7 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) last_stack = zone + rz_size; usable_stack_size = size; - stack_size = size + rz_size; + ngx_thread_stack_size = size + rz_size; /* allow the spinlock in libc malloc() */ __isthreaded = 1; @@ -212,28 +236,6 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) } -static inline int ngx_gettid() -{ - char *sp; - - if (stack_size == 0) { - return 0; - } - -#if ( __i386__ ) - - __asm__ volatile ("mov %%esp, %0" : "=q" (sp)); - -#elif ( __amd64__ ) - - __asm__ volatile ("mov %%rsp, %0" : "=q" (sp)); - -#endif - - return (usrstack - sp) / stack_size; -} - - ngx_tid_t ngx_thread_self() { int tid; @@ -313,7 +315,7 @@ void ngx_mutex_done(ngx_mutex_t *m) } -ngx_int_t ngx_mutex_do_lock(ngx_mutex_t *m, ngx_int_t try) +ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) { uint32_t lock, new, old; ngx_uint_t tries; @@ -453,7 +455,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) old = m->lock; if (!(old & NGX_MUTEX_LOCK_BUSY)) { - ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, + ngx_log_error(NGX_LOG_ALERT, m->log, 0, "tring to unlock the free mutex " PTR_FMT, m); return NGX_ERROR; } diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c index 24753c427..2fcd6f333 100644 --- a/src/os/unix/ngx_freebsd_sendfile_chain.c +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c @@ -1,4 +1,9 @@ +/* + * Copyright (C) 2002-2004 Igor Sysoev, http://sysoev.ru/en/ + */ + + #include <ngx_config.h> #include <ngx_core.h> #include <ngx_event.h> diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c index 4fa8f835c..463fddac7 100644 --- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -1,4 +1,9 @@ +/* + * Copyright (C) 2002-2004 Igor Sysoev, http://sysoev.ru/en/ + */ + + #include <ngx_config.h> #include <ngx_core.h> #include <ngx_event.h> diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index a8c9610b2..3210819f7 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -13,9 +13,12 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, ngx_spawn_proc_pt proc, void *data, char *name, ngx_int_t respawn) { +#if 0 sigset_t set, oset; +#endif ngx_pid_t pid; +#if 0 if (respawn < 0) { sigemptyset(&set); sigaddset(&set, SIGCHLD); @@ -25,6 +28,7 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, return NGX_ERROR; } } +#endif pid = fork(); @@ -34,11 +38,13 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, } if (pid == -1 || pid == 0) { +#if 0 if (sigprocmask(SIG_SETMASK, &oset, &set) == -1) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "sigprocmask() failed while spawning %s", name); return NGX_ERROR; } +#endif } switch (pid) { @@ -75,11 +81,13 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, ngx_processes[ngx_last_process].exiting = 0; ngx_last_process++; +#if 0 if (sigprocmask(SIG_SETMASK, &oset, &set) == -1) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "sigprocmask() failed while spawning %s", name); return NGX_ERROR; } +#endif return pid; } diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c index 9cd1618a3..f428261d3 100644 --- a/src/os/unix/ngx_solaris_sendfilev_chain.c +++ b/src/os/unix/ngx_solaris_sendfilev_chain.c @@ -1,4 +1,9 @@ +/* + * Copyright (C) 2002-2004 Igor Sysoev, http://sysoev.ru/en/ + */ + + #include <ngx_config.h> #include <ngx_core.h> #include <ngx_event.h> diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h index 3961f328f..8a02880bb 100644 --- a/src/os/unix/ngx_thread.h +++ b/src/os/unix/ngx_thread.h @@ -15,12 +15,11 @@ typedef pid_t ngx_tid_t; -#define TID_T_FMT PID_T_FMT - -#define ngx_log_tid 0 - #undef ngx_log_pid #define ngx_log_pid ngx_thread_self() +#define ngx_log_tid 0 + +#define TID_T_FMT PID_T_FMT #define NGX_MUTEX_LIGHT 1 @@ -35,12 +34,43 @@ typedef volatile struct { } ngx_mutex_t; +extern char *ngx_freebsd_kern_usrstack; +extern size_t ngx_thread_stack_size; + +static inline int ngx_gettid() +{ + char *sp; + + if (ngx_thread_stack_size == 0) { + return 0; + } + +#if ( __i386__ ) + + __asm__ volatile ("mov %%esp, %0" : "=q" (sp)); + +#elif ( __amd64__ ) + + __asm__ volatile ("mov %%rsp, %0" : "=q" (sp)); + +#else + +#error "rfork()ed threads are not supported on this platform" + +#endif + + return (ngx_freebsd_kern_usrstack - sp) / ngx_thread_stack_size; +} + + + #else /* use pthreads */ #include <pthread.h> typedef pthread_t ngx_tid_t; +#define ngx_gettid() ((ngx_int_t) pthread_getspecific(0)) #define ngx_log_tid ngx_thread_self() #endif @@ -51,12 +81,13 @@ int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg, ngx_log_t *log); ngx_tid_t ngx_thread_self(); + ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags); void ngx_mutex_done(ngx_mutex_t *m); -#define ngx_mutex_trylock(m) ngx_mutex_do_lock(m, 1) -#define ngx_mutex_lock(m) ngx_mutex_do_lock(m, 0) -ngx_int_t ngx_mutex_do_lock(ngx_mutex_t *m, ngx_int_t try); +#define ngx_mutex_trylock(m) ngx_mutex_dolock(m, 1) +#define ngx_mutex_lock(m) ngx_mutex_dolock(m, 0) +ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try); ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m); |