aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix/ngx_thread.h
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-02-29 21:03:02 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-02-29 21:03:02 +0000
commitd94049b6320504f3213adfaad939493676e83a3a (patch)
tree7a25b794030cbee22cca6e2bf27aa3569f915d2c /src/os/unix/ngx_thread.h
parent898446c8bacb5b0e1c223dfec4643ebee8d07f8e (diff)
downloadnginx-d94049b6320504f3213adfaad939493676e83a3a.tar.gz
nginx-d94049b6320504f3213adfaad939493676e83a3a.zip
nginx-0.0.2-2004-03-01-00:03:02 import
Diffstat (limited to 'src/os/unix/ngx_thread.h')
-rw-r--r--src/os/unix/ngx_thread.h45
1 files changed, 38 insertions, 7 deletions
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);