Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ngx_thread.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) Nginx, Inc.
5  */
6 
7 
8 #ifndef _NGX_THREAD_H_INCLUDED_
9 #define _NGX_THREAD_H_INCLUDED_
10 
11 
12 #include <ngx_config.h>
13 #include <ngx_core.h>
14 
15 #if (NGX_THREADS)
16 
17 #define NGX_MAX_THREADS 128
18 
19 #if (NGX_USE_RFORK)
21 
22 
23 #else /* use pthreads */
24 
25 #include <pthread.h>
26 
27 typedef pthread_t ngx_tid_t;
28 
29 #define ngx_thread_self() pthread_self()
30 #define ngx_log_tid (int) ngx_thread_self()
31 
32 #if (NGX_FREEBSD) && !(NGX_LINUXTHREADS)
33 #define NGX_TID_T_FMT "%p"
34 #else
35 #define NGX_TID_T_FMT "%d"
36 #endif
37 
38 
39 typedef pthread_key_t ngx_tls_key_t;
40 
41 #define ngx_thread_key_create(key) pthread_key_create(key, NULL)
42 #define ngx_thread_key_create_n "pthread_key_create()"
43 #define ngx_thread_set_tls pthread_setspecific
44 #define ngx_thread_set_tls_n "pthread_setspecific()"
45 #define ngx_thread_get_tls pthread_getspecific
46 
47 
48 #define NGX_MUTEX_LIGHT 0
49 
50 typedef struct {
51  pthread_mutex_t mutex;
52  ngx_log_t *log;
53 } ngx_mutex_t;
54 
55 typedef struct {
56  pthread_cond_t cond;
57  ngx_log_t *log;
58 } ngx_cond_t;
59 
60 #define ngx_thread_sigmask pthread_sigmask
61 #define ngx_thread_sigmask_n "pthread_sigmask()"
62 
63 #define ngx_thread_join(t, p) pthread_join(t, p)
64 
65 #define ngx_setthrtitle(n)
66 
67 
68 
72 
73 #endif
74 
75 
76 #define ngx_thread_volatile volatile
77 
78 
79 typedef struct {
80  ngx_tid_t tid;
81  ngx_cond_t *cv;
82  ngx_uint_t state;
83 } ngx_thread_t;
84 
85 #define NGX_THREAD_FREE 1
86 #define NGX_THREAD_BUSY 2
87 #define NGX_THREAD_EXIT 3
88 #define NGX_THREAD_DONE 4
89 
90 extern ngx_int_t ngx_threads_n;
91 extern volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS];
92 
93 
94 typedef void * ngx_thread_value_t;
95 
96 ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle);
98  ngx_thread_value_t (*func)(void *arg), void *arg, ngx_log_t *log);
99 
102 
103 
105 void ngx_cond_destroy(ngx_cond_t *cv);
108 
109 
110 #else /* !NGX_THREADS */
111 
112 #define ngx_thread_volatile
113 
114 #define ngx_log_tid 0
115 #define NGX_TID_T_FMT "%d"
116 
117 #define ngx_mutex_trylock(m) NGX_OK
118 #define ngx_mutex_lock(m)
119 #define ngx_mutex_unlock(m)
120 
121 #define ngx_cond_signal(cv)
122 
123 #define ngx_thread_main() 1
124 
125 #endif
126 
127 
128 #endif /* _NGX_THREAD_H_INCLUDED_ */