aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix/ngx_thread.h
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-07-05 06:55:54 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-07-05 06:55:54 +0000
commit32fcd5cf64b9f55f9184e98e39f1b2152321a710 (patch)
treef349f2fb8106ba4490ec3f47e7330f160f6f5f9b /src/os/unix/ngx_thread.h
parent98c1cf18c1a4ffb14ded78e93359f87ee7bdeed4 (diff)
downloadnginx-32fcd5cf64b9f55f9184e98e39f1b2152321a710.tar.gz
nginx-32fcd5cf64b9f55f9184e98e39f1b2152321a710.zip
nginx-0.0.7-2004-07-05-10:55:54 import
Diffstat (limited to 'src/os/unix/ngx_thread.h')
-rw-r--r--src/os/unix/ngx_thread.h107
1 files changed, 40 insertions, 67 deletions
diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h
index a1404038e..3bd9753d7 100644
--- a/src/os/unix/ngx_thread.h
+++ b/src/os/unix/ngx_thread.h
@@ -7,111 +7,84 @@
#if (NGX_THREADS)
-#define ngx_thread_volatile volatile
+#define NGX_MAX_THREADS 128
#if (NGX_USE_RFORK)
+#include <ngx_freebsd_rfork_thread.h>
-#include <sys/ipc.h>
-#include <sys/sem.h>
-#include <sched.h>
-typedef pid_t ngx_tid_t;
+#else /* use pthreads */
-#undef ngx_log_pid
-#define ngx_log_pid ngx_thread_self()
-#define ngx_log_tid 0
+#include <pthread.h>
+#include <pthread_np.h>
-#define TID_T_FMT PID_T_FMT
+typedef pthread_t ngx_tid_t;
+#define ngx_thread_self() pthread_self()
+#define ngx_thread_main() pthread_main_np()
+#define ngx_log_tid (int) ngx_thread_self()
-#define NGX_MUTEX_LIGHT 1
-#define NGX_MUTEX_CV 2
+#define TID_T_FMT PTR_FMT
-#define NGX_MUTEX_LOCK_BUSY 0x80000000
-typedef volatile struct {
- ngx_atomic_t lock;
- ngx_log_t *log;
- int semid;
-} ngx_mutex_t;
+#define NGX_MUTEX_LIGHT 0
+typedef struct {
+ pthread_mutex_t mutex;
+ ngx_log_t *log;
+} ngx_mutex_t;
typedef struct {
- int semid;
- ngx_log_t *log;
+ pthread_cond_t cond;
+ ngx_tid_t tid;
+ ngx_log_t *log;
} ngx_cond_t;
+#define ngx_thread_sigmask pthread_sigmask
+#define ngx_thread_sigmask_n "pthread_sigmask()"
-#define ngx_thread_sigmask(how, set, oset) \
- (sigprocmask(how, set, oset) == -1) ? ngx_errno : 0
-
-#define ngx_thread_sigmask_n "sigprocmask()"
-
-
-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));
+#define ngx_thread_join(t, p) pthread_join(t, p)
-#elif ( __amd64__ )
+#define ngx_setthrtitle(n)
- __asm__ volatile ("mov %%rsp, %0" : "=q" (sp));
-#else
-#error "rfork()ed threads are not supported on this platform"
+ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m);
+ngx_int_t ngx_mutex_lock(ngx_mutex_t *m);
+ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m);
#endif
- return (ngx_freebsd_kern_usrstack - sp) / ngx_thread_stack_size;
-}
-
-
-#define ngx_thread_main() (ngx_gettid() == 0)
-
-#else /* use pthreads */
-
-#include <pthread.h>
+#define ngx_thread_volatile volatile
-typedef pthread_t ngx_tid_t;
-#define ngx_gettid() ((ngx_int_t) pthread_getspecific(0))
-#define ngx_log_tid ngx_thread_self()
+typedef struct {
+ ngx_tid_t tid;
+ ngx_cond_t *cv;
+ ngx_uint_t state;
+} ngx_thread_t;
-#define ngx_thread_sigmask pthread_sigmask
-#define ngx_thread_sigmask_n "pthread_sigmask()"
+#define NGX_THREAD_FREE 1
+#define NGX_THREAD_BUSY 2
+#define NGX_THREAD_EXIT 3
+#define NGX_THREAD_DONE 4
-#endif
+extern ngx_int_t ngx_threads_n;
+extern volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS];
ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle);
-int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg,
+int ngx_create_thread(ngx_tid_t *tid, void* (*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_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);
+void ngx_mutex_destroy(ngx_mutex_t *m);
ngx_cond_t *ngx_cond_init(ngx_log_t *log);
-void ngx_cond_done(ngx_cond_t *cv);
+void ngx_cond_destroy(ngx_cond_t *cv);
ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m);
ngx_int_t ngx_cond_signal(ngx_cond_t *cv);