Mercurial > hg > nginx-quic
diff src/os/unix/ngx_thread.h @ 272:d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 29 Feb 2004 21:03:02 +0000 |
parents | e16dfb9b9afa |
children | b836469c37c3 |
line wrap: on
line diff
--- 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 - +#undef ngx_log_pid +#define ngx_log_pid ngx_thread_self() #define ngx_log_tid 0 -#undef ngx_log_pid -#define ngx_log_pid ngx_thread_self() +#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, in 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);