Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_thread.h @ 5707:31dd63dcb9ea
Events: use eventfd() instead of syscall(SYS_eventfd) if possible.
This fixes --with-file-aio support on systems that lack eventfd()
syscall, notably aarch64 Linux.
The syscall(SYS_eventfd) may still be necessary on systems that
have eventfd() syscall in the kernel but lack it in glibc, e.g.
as seen in the current CentOS 5 release.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 23 May 2014 16:37:05 +0400 |
parents | d620f497c50f |
children | 457ec43dd8d5 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
383
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
383
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
383
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
383
diff
changeset
|
6 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
383
diff
changeset
|
7 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #ifndef _NGX_THREAD_H_INCLUDED_ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #define _NGX_THREAD_H_INCLUDED_ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 #include <ngx_config.h> |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 #include <ngx_core.h> |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 #if (NGX_THREADS) |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
17 #define NGX_MAX_THREADS 128 |
275
b836469c37c3
nginx-0.0.2-2004-03-02-18:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
18 |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
267
diff
changeset
|
19 #if (NGX_USE_RFORK) |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
20 #include <ngx_freebsd_rfork_thread.h> |
372
c9fdfccebc49
nginx-0.0.7-2004-06-29-01:03:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
21 |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
22 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 #else /* use pthreads */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 #include <pthread.h> |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
27 typedef pthread_t ngx_tid_t; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
29 #define ngx_thread_self() pthread_self() |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
30 #define ngx_log_tid (int) ngx_thread_self() |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
31 |
455 | 32 #if (NGX_FREEBSD) && !(NGX_LINUXTHREADS) |
461 | 33 #define NGX_TID_T_FMT "%p" |
382
449c4885dcd1
nginx-0.0.7-2004-07-07-23:48:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
34 #else |
461 | 35 #define NGX_TID_T_FMT "%d" |
382
449c4885dcd1
nginx-0.0.7-2004-07-07-23:48:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
381
diff
changeset
|
36 #endif |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
37 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
38 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
39 typedef pthread_key_t ngx_tls_key_t; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
40 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
41 #define ngx_thread_key_create(key) pthread_key_create(key, NULL) |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
42 #define ngx_thread_key_create_n "pthread_key_create()" |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
43 #define ngx_thread_set_tls pthread_setspecific |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
44 #define ngx_thread_set_tls_n "pthread_setspecific()" |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
45 #define ngx_thread_get_tls pthread_getspecific |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
46 |
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
47 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
48 #define NGX_MUTEX_LIGHT 0 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
49 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
50 typedef struct { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
51 pthread_mutex_t mutex; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
52 ngx_log_t *log; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
53 } ngx_mutex_t; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
54 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
55 typedef struct { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
56 pthread_cond_t cond; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
57 ngx_log_t *log; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
58 } ngx_cond_t; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 |
279
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
277
diff
changeset
|
60 #define ngx_thread_sigmask pthread_sigmask |
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
277
diff
changeset
|
61 #define ngx_thread_sigmask_n "pthread_sigmask()" |
b79f021a644a
nginx-0.0.2-2004-03-04-19:34:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
277
diff
changeset
|
62 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
63 #define ngx_thread_join(t, p) pthread_join(t, p) |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
64 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
65 #define ngx_setthrtitle(n) |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
66 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
67 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
68 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
69 ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m); |
563 | 70 void ngx_mutex_lock(ngx_mutex_t *m); |
71 void ngx_mutex_unlock(ngx_mutex_t *m); | |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
72 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 #endif |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
76 #define ngx_thread_volatile volatile |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
77 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
78 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
79 typedef struct { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
80 ngx_tid_t tid; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
81 ngx_cond_t *cv; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
82 ngx_uint_t state; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
83 } ngx_thread_t; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
84 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
85 #define NGX_THREAD_FREE 1 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
86 #define NGX_THREAD_BUSY 2 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
87 #define NGX_THREAD_EXIT 3 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
88 #define NGX_THREAD_DONE 4 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
89 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
90 extern ngx_int_t ngx_threads_n; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
91 extern volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS]; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
92 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
93 |
563 | 94 typedef void * ngx_thread_value_t; |
95 | |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
267
diff
changeset
|
96 ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle); |
563 | 97 ngx_err_t ngx_create_thread(ngx_tid_t *tid, |
98 ngx_thread_value_t (*func)(void *arg), void *arg, ngx_log_t *log); | |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
99 |
461 | 100 ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags); |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
101 void ngx_mutex_destroy(ngx_mutex_t *m); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
104 ngx_cond_t *ngx_cond_init(ngx_log_t *log); |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
105 void ngx_cond_destroy(ngx_cond_t *cv); |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
106 ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m); |
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
107 ngx_int_t ngx_cond_signal(ngx_cond_t *cv); |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
108 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
109 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 #else /* !NGX_THREADS */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 |
275
b836469c37c3
nginx-0.0.2-2004-03-02-18:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
112 #define ngx_thread_volatile |
b836469c37c3
nginx-0.0.2-2004-03-02-18:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
113 |
461 | 114 #define ngx_log_tid 0 |
115 #define NGX_TID_T_FMT "%d" | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 |
383
c05876036128
nginx-0.0.7-2004-07-08-19:17:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
382
diff
changeset
|
117 #define ngx_mutex_trylock(m) NGX_OK |
563 | 118 #define ngx_mutex_lock(m) |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 #define ngx_mutex_unlock(m) |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
372
c9fdfccebc49
nginx-0.0.7-2004-06-29-01:03:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
121 #define ngx_cond_signal(cv) |
c9fdfccebc49
nginx-0.0.7-2004-06-29-01:03:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
122 |
c9fdfccebc49
nginx-0.0.7-2004-06-29-01:03:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
123 #define ngx_thread_main() 1 |
c9fdfccebc49
nginx-0.0.7-2004-06-29-01:03:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
124 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 #endif |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 #endif /* _NGX_THREAD_H_INCLUDED_ */ |