From d94049b6320504f3213adfaad939493676e83a3a Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Sun, 29 Feb 2004 21:03:02 +0000 Subject: nginx-0.0.2-2004-03-01-00:03:02 import --- src/os/unix/ngx_thread.h | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'src/os/unix/ngx_thread.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 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); -- cgit v1.2.3