Mercurial > hg > nginx-quic
comparison 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 |
comparison
equal
deleted
inserted
replaced
271:e16dfb9b9afa | 272:d4e65d74db9f |
---|---|
13 #include <sys/sem.h> | 13 #include <sys/sem.h> |
14 #include <sched.h> | 14 #include <sched.h> |
15 | 15 |
16 typedef pid_t ngx_tid_t; | 16 typedef pid_t ngx_tid_t; |
17 | 17 |
18 #define TID_T_FMT PID_T_FMT | 18 #undef ngx_log_pid |
19 | 19 #define ngx_log_pid ngx_thread_self() |
20 #define ngx_log_tid 0 | 20 #define ngx_log_tid 0 |
21 | 21 |
22 #undef ngx_log_pid | 22 #define TID_T_FMT PID_T_FMT |
23 #define ngx_log_pid ngx_thread_self() | |
24 | 23 |
25 | 24 |
26 #define NGX_MUTEX_LIGHT 1 | 25 #define NGX_MUTEX_LIGHT 1 |
27 #define NGX_MUTEX_CV 2 | 26 #define NGX_MUTEX_CV 2 |
28 | 27 |
33 ngx_log_t *log; | 32 ngx_log_t *log; |
34 int semid; | 33 int semid; |
35 } ngx_mutex_t; | 34 } ngx_mutex_t; |
36 | 35 |
37 | 36 |
37 extern char *ngx_freebsd_kern_usrstack; | |
38 extern size_t ngx_thread_stack_size; | |
39 | |
40 static inline int ngx_gettid() | |
41 { | |
42 char *sp; | |
43 | |
44 if (ngx_thread_stack_size == 0) { | |
45 return 0; | |
46 } | |
47 | |
48 #if ( __i386__ ) | |
49 | |
50 __asm__ volatile ("mov %%esp, %0" : "=q" (sp)); | |
51 | |
52 #elif ( __amd64__ ) | |
53 | |
54 __asm__ volatile ("mov %%rsp, %0" : "=q" (sp)); | |
55 | |
56 #else | |
57 | |
58 #error "rfork()ed threads are not supported on this platform" | |
59 | |
60 #endif | |
61 | |
62 return (ngx_freebsd_kern_usrstack - sp) / ngx_thread_stack_size; | |
63 } | |
64 | |
65 | |
66 | |
38 #else /* use pthreads */ | 67 #else /* use pthreads */ |
39 | 68 |
40 #include <pthread.h> | 69 #include <pthread.h> |
41 | 70 |
42 typedef pthread_t ngx_tid_t; | 71 typedef pthread_t ngx_tid_t; |
43 | 72 |
73 #define ngx_gettid() ((ngx_int_t) pthread_getspecific(0)) | |
44 #define ngx_log_tid ngx_thread_self() | 74 #define ngx_log_tid ngx_thread_self() |
45 | 75 |
46 #endif | 76 #endif |
47 | 77 |
48 | 78 |
49 ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle); | 79 ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle); |
50 int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg, | 80 int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg, |
51 ngx_log_t *log); | 81 ngx_log_t *log); |
52 ngx_tid_t ngx_thread_self(); | 82 ngx_tid_t ngx_thread_self(); |
53 | 83 |
84 | |
54 ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags); | 85 ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags); |
55 void ngx_mutex_done(ngx_mutex_t *m); | 86 void ngx_mutex_done(ngx_mutex_t *m); |
56 | 87 |
57 #define ngx_mutex_trylock(m) ngx_mutex_do_lock(m, 1) | 88 #define ngx_mutex_trylock(m) ngx_mutex_dolock(m, 1) |
58 #define ngx_mutex_lock(m) ngx_mutex_do_lock(m, 0) | 89 #define ngx_mutex_lock(m) ngx_mutex_dolock(m, 0) |
59 ngx_int_t ngx_mutex_do_lock(ngx_mutex_t *m, ngx_int_t try); | 90 ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try); |
60 ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m); | 91 ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m); |
61 | 92 |
62 | 93 |
63 extern ngx_int_t ngx_threaded; | 94 extern ngx_int_t ngx_threaded; |
64 | 95 |