Mercurial > hg > nginx-quic
annotate src/core/ngx_thread_pool.c @ 6038:94ce52db3367
Removed stub implementation of win32 mutexes.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 23 Mar 2015 13:52:47 +0300 |
parents | 67717d4e4f47 |
children | fc36690e7f44 |
rev | line source |
---|---|
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
1 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
2 /* |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
3 * Copyright (C) Nginx, Inc. |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
4 * Copyright (C) Valentin V. Bartenev |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
5 * Copyright (C) Ruslan Ermilov |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
6 */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
7 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
8 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
9 #include <ngx_config.h> |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
10 #include <ngx_core.h> |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
11 #include <ngx_thread_pool.h> |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
12 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
13 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
14 typedef struct { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
15 ngx_array_t pools; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
16 } ngx_thread_pool_conf_t; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
17 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
18 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
19 typedef struct { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
20 ngx_thread_mutex_t mtx; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
21 ngx_thread_task_t *first; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
22 ngx_thread_task_t **last; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
23 } ngx_thread_pool_queue_t; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
24 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
25 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
26 struct ngx_thread_pool_s { |
6025
32099b107191
Thread pools: keep waiting tasks counter in ngx_thread_pool_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6018
diff
changeset
|
27 ngx_thread_pool_queue_t queue; |
6026
25fda43e3bcb
Thread pools: fixed the waiting tasks accounting.
Ruslan Ermilov <ru@nginx.com>
parents:
6025
diff
changeset
|
28 ngx_int_t waiting; |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
29 ngx_thread_cond_t cond; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
30 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
31 ngx_log_t *log; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
32 ngx_pool_t *pool; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
33 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
34 ngx_str_t name; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
35 ngx_uint_t threads; |
6026
25fda43e3bcb
Thread pools: fixed the waiting tasks accounting.
Ruslan Ermilov <ru@nginx.com>
parents:
6025
diff
changeset
|
36 ngx_int_t max_queue; |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
37 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
38 u_char *file; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
39 ngx_uint_t line; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
40 }; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
41 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
42 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
43 static ngx_int_t ngx_thread_pool_init(ngx_thread_pool_t *tp, ngx_log_t *log, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
44 ngx_pool_t *pool); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
45 static ngx_int_t ngx_thread_pool_queue_init(ngx_thread_pool_queue_t *queue, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
46 ngx_log_t *log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
47 static ngx_int_t ngx_thread_pool_queue_destroy(ngx_thread_pool_queue_t *queue, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
48 ngx_log_t *log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
49 static void ngx_thread_pool_destroy(ngx_thread_pool_t *tp); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
50 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
51 static void *ngx_thread_pool_cycle(void *data); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
52 static void ngx_thread_pool_handler(ngx_event_t *ev); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
53 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
54 static char *ngx_thread_pool(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
55 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
56 static void *ngx_thread_pool_create_conf(ngx_cycle_t *cycle); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
57 static char *ngx_thread_pool_init_conf(ngx_cycle_t *cycle, void *conf); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
58 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
59 static ngx_int_t ngx_thread_pool_init_worker(ngx_cycle_t *cycle); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
60 static void ngx_thread_pool_exit_worker(ngx_cycle_t *cycle); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
61 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
62 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
63 static ngx_command_t ngx_thread_pool_commands[] = { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
64 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
65 { ngx_string("thread_pool"), |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
66 NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE23, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
67 ngx_thread_pool, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
68 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
69 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
70 NULL }, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
71 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
72 ngx_null_command |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
73 }; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
74 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
75 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
76 static ngx_core_module_t ngx_thread_pool_module_ctx = { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
77 ngx_string("thread_pool"), |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
78 ngx_thread_pool_create_conf, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
79 ngx_thread_pool_init_conf |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
80 }; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
81 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
82 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
83 ngx_module_t ngx_thread_pool_module = { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
84 NGX_MODULE_V1, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
85 &ngx_thread_pool_module_ctx, /* module context */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
86 ngx_thread_pool_commands, /* module directives */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
87 NGX_CORE_MODULE, /* module type */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
88 NULL, /* init master */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
89 NULL, /* init module */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
90 ngx_thread_pool_init_worker, /* init process */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
91 NULL, /* init thread */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
92 NULL, /* exit thread */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
93 ngx_thread_pool_exit_worker, /* exit process */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
94 NULL, /* exit master */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
95 NGX_MODULE_V1_PADDING |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
96 }; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
97 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
98 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
99 static ngx_str_t ngx_thread_pool_default = ngx_string("default"); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
100 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
101 static ngx_uint_t ngx_thread_pool_task_id; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
102 static ngx_thread_pool_queue_t ngx_thread_pool_done; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
103 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
104 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
105 static ngx_int_t |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
106 ngx_thread_pool_init(ngx_thread_pool_t *tp, ngx_log_t *log, ngx_pool_t *pool) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
107 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
108 int err; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
109 pthread_t tid; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
110 ngx_uint_t n; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
111 pthread_attr_t attr; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
112 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
113 if (ngx_notify == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
114 ngx_log_error(NGX_LOG_ALERT, log, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
115 "the configured event method cannot be used with thread pools"); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
116 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
117 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
118 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
119 if (ngx_thread_pool_queue_init(&tp->queue, log) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
120 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
121 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
122 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
123 if (ngx_thread_cond_create(&tp->cond, log) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
124 (void) ngx_thread_pool_queue_destroy(&tp->queue, log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
125 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
126 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
127 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
128 tp->log = log; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
129 tp->pool = pool; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
130 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
131 err = pthread_attr_init(&attr); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
132 if (err) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
133 ngx_log_error(NGX_LOG_ALERT, log, err, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
134 "pthread_attr_init() failed"); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
135 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
136 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
137 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
138 #if 0 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
139 err = pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
140 if (err) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
141 ngx_log_error(NGX_LOG_ALERT, log, err, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
142 "pthread_attr_setstacksize() failed"); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
143 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
144 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
145 #endif |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
146 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
147 for (n = 0; n < tp->threads; n++) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
148 err = pthread_create(&tid, &attr, ngx_thread_pool_cycle, tp); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
149 if (err) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
150 ngx_log_error(NGX_LOG_ALERT, log, err, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
151 "pthread_create() failed"); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
152 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
153 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
154 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
155 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
156 (void) pthread_attr_destroy(&attr); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
157 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
158 return NGX_OK; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
159 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
160 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
161 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
162 static ngx_int_t |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
163 ngx_thread_pool_queue_init(ngx_thread_pool_queue_t *queue, ngx_log_t *log) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
164 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
165 queue->first = NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
166 queue->last = &queue->first; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
167 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
168 return ngx_thread_mutex_create(&queue->mtx, log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
169 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
170 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
171 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
172 static ngx_int_t |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
173 ngx_thread_pool_queue_destroy(ngx_thread_pool_queue_t *queue, ngx_log_t *log) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
174 { |
6027
67717d4e4f47
Thread pools: silence warning on process exit.
Ruslan Ermilov <ru@nginx.com>
parents:
6026
diff
changeset
|
175 #if 0 |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
176 return ngx_thread_mutex_destroy(&queue->mtx, log); |
6027
67717d4e4f47
Thread pools: silence warning on process exit.
Ruslan Ermilov <ru@nginx.com>
parents:
6026
diff
changeset
|
177 #else |
67717d4e4f47
Thread pools: silence warning on process exit.
Ruslan Ermilov <ru@nginx.com>
parents:
6026
diff
changeset
|
178 return NGX_OK; |
67717d4e4f47
Thread pools: silence warning on process exit.
Ruslan Ermilov <ru@nginx.com>
parents:
6026
diff
changeset
|
179 #endif |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
180 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
181 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
182 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
183 static void |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
184 ngx_thread_pool_destroy(ngx_thread_pool_t *tp) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
185 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
186 /* TODO: exit threads */ |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
187 |
6027
67717d4e4f47
Thread pools: silence warning on process exit.
Ruslan Ermilov <ru@nginx.com>
parents:
6026
diff
changeset
|
188 #if 0 |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
189 (void) ngx_thread_cond_destroy(&tp->cond, tp->log); |
6027
67717d4e4f47
Thread pools: silence warning on process exit.
Ruslan Ermilov <ru@nginx.com>
parents:
6026
diff
changeset
|
190 #endif |
67717d4e4f47
Thread pools: silence warning on process exit.
Ruslan Ermilov <ru@nginx.com>
parents:
6026
diff
changeset
|
191 |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
192 (void) ngx_thread_pool_queue_destroy(&tp->queue, tp->log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
193 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
194 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
195 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
196 ngx_thread_task_t * |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
197 ngx_thread_task_alloc(ngx_pool_t *pool, size_t size) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
198 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
199 ngx_thread_task_t *task; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
200 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
201 task = ngx_pcalloc(pool, sizeof(ngx_thread_task_t) + size); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
202 if (task == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
203 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
204 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
205 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
206 task->ctx = task + 1; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
207 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
208 return task; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
209 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
210 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
211 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
212 ngx_int_t |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
213 ngx_thread_task_post(ngx_thread_pool_t *tp, ngx_thread_task_t *task) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
214 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
215 if (task->event.active) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
216 ngx_log_error(NGX_LOG_ALERT, tp->log, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
217 "task #%ui already active", task->id); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
218 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
219 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
220 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
221 if (ngx_thread_mutex_lock(&tp->queue.mtx, tp->log) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
222 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
223 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
224 |
6025
32099b107191
Thread pools: keep waiting tasks counter in ngx_thread_pool_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6018
diff
changeset
|
225 if (tp->waiting >= tp->max_queue) { |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
226 (void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
227 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
228 ngx_log_error(NGX_LOG_ERR, tp->log, 0, |
6026
25fda43e3bcb
Thread pools: fixed the waiting tasks accounting.
Ruslan Ermilov <ru@nginx.com>
parents:
6025
diff
changeset
|
229 "thread pool \"%V\" queue overflow: %i tasks waiting", |
6025
32099b107191
Thread pools: keep waiting tasks counter in ngx_thread_pool_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6018
diff
changeset
|
230 &tp->name, tp->waiting); |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
231 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
232 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
233 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
234 task->event.active = 1; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
235 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
236 task->id = ngx_thread_pool_task_id++; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
237 task->next = NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
238 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
239 if (ngx_thread_cond_signal(&tp->cond, tp->log) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
240 (void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
241 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
242 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
243 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
244 *tp->queue.last = task; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
245 tp->queue.last = &task->next; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
246 |
6025
32099b107191
Thread pools: keep waiting tasks counter in ngx_thread_pool_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6018
diff
changeset
|
247 tp->waiting++; |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
248 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
249 (void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
250 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
251 ngx_log_debug2(NGX_LOG_DEBUG_CORE, tp->log, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
252 "task #%ui added to thread pool \"%V\"", |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
253 task->id, &tp->name); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
254 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
255 return NGX_OK; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
256 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
257 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
258 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
259 static void * |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
260 ngx_thread_pool_cycle(void *data) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
261 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
262 ngx_thread_pool_t *tp = data; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
263 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
264 int err; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
265 sigset_t set; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
266 ngx_thread_task_t *task; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
267 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
268 #if 0 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
269 ngx_time_update(); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
270 #endif |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
271 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
272 ngx_log_debug1(NGX_LOG_DEBUG_CORE, tp->log, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
273 "thread in pool \"%V\" started", &tp->name); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
274 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
275 sigfillset(&set); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
276 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
277 sigdelset(&set, SIGILL); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
278 sigdelset(&set, SIGFPE); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
279 sigdelset(&set, SIGSEGV); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
280 sigdelset(&set, SIGBUS); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
281 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
282 err = pthread_sigmask(SIG_BLOCK, &set, NULL); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
283 if (err) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
284 ngx_log_error(NGX_LOG_ALERT, tp->log, err, "pthread_sigmask() failed"); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
285 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
286 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
287 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
288 for ( ;; ) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
289 if (ngx_thread_mutex_lock(&tp->queue.mtx, tp->log) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
290 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
291 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
292 |
6026
25fda43e3bcb
Thread pools: fixed the waiting tasks accounting.
Ruslan Ermilov <ru@nginx.com>
parents:
6025
diff
changeset
|
293 /* the number may become negative */ |
25fda43e3bcb
Thread pools: fixed the waiting tasks accounting.
Ruslan Ermilov <ru@nginx.com>
parents:
6025
diff
changeset
|
294 tp->waiting--; |
25fda43e3bcb
Thread pools: fixed the waiting tasks accounting.
Ruslan Ermilov <ru@nginx.com>
parents:
6025
diff
changeset
|
295 |
25fda43e3bcb
Thread pools: fixed the waiting tasks accounting.
Ruslan Ermilov <ru@nginx.com>
parents:
6025
diff
changeset
|
296 while (tp->queue.first == NULL) { |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
297 if (ngx_thread_cond_wait(&tp->cond, &tp->queue.mtx, tp->log) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
298 != NGX_OK) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
299 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
300 (void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
301 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
302 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
303 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
304 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
305 task = tp->queue.first; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
306 tp->queue.first = task->next; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
307 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
308 if (tp->queue.first == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
309 tp->queue.last = &tp->queue.first; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
310 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
311 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
312 if (ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
313 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
314 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
315 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
316 #if 0 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
317 ngx_time_update(); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
318 #endif |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
319 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
320 ngx_log_debug2(NGX_LOG_DEBUG_CORE, tp->log, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
321 "run task #%ui in thread pool \"%V\"", |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
322 task->id, &tp->name); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
323 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
324 task->handler(task->ctx, tp->log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
325 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
326 ngx_log_debug2(NGX_LOG_DEBUG_CORE, tp->log, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
327 "complete task #%ui in thread pool \"%V\"", |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
328 task->id, &tp->name); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
329 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
330 task->next = NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
331 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
332 if (ngx_thread_mutex_lock(&ngx_thread_pool_done.mtx, tp->log) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
333 != NGX_OK) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
334 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
335 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
336 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
337 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
338 *ngx_thread_pool_done.last = task; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
339 ngx_thread_pool_done.last = &task->next; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
340 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
341 if (ngx_thread_mutex_unlock(&ngx_thread_pool_done.mtx, tp->log) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
342 != NGX_OK) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
343 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
344 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
345 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
346 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
347 (void) ngx_notify(ngx_thread_pool_handler); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
348 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
349 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
350 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
351 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
352 static void |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
353 ngx_thread_pool_handler(ngx_event_t *ev) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
354 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
355 ngx_event_t *event; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
356 ngx_thread_task_t *task; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
357 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
358 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ev->log, 0, "thread pool handler"); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
359 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
360 if (ngx_thread_mutex_lock(&ngx_thread_pool_done.mtx, ev->log) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
361 return; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
362 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
363 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
364 task = ngx_thread_pool_done.first; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
365 ngx_thread_pool_done.first = NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
366 ngx_thread_pool_done.last = &ngx_thread_pool_done.first; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
367 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
368 if (ngx_thread_mutex_unlock(&ngx_thread_pool_done.mtx, ev->log) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
369 return; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
370 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
371 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
372 while (task) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
373 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
374 "run completion handler for task #%ui", task->id); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
375 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
376 event = &task->event; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
377 task = task->next; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
378 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
379 event->complete = 1; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
380 event->active = 0; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
381 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
382 event->handler(event); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
383 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
384 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
385 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
386 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
387 static void * |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
388 ngx_thread_pool_create_conf(ngx_cycle_t *cycle) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
389 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
390 ngx_thread_pool_conf_t *tcf; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
391 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
392 tcf = ngx_pcalloc(cycle->pool, sizeof(ngx_thread_pool_conf_t)); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
393 if (tcf == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
394 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
395 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
396 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
397 if (ngx_array_init(&tcf->pools, cycle->pool, 4, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
398 sizeof(ngx_thread_pool_t *)) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
399 != NGX_OK) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
400 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
401 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
402 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
403 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
404 return tcf; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
405 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
406 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
407 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
408 static char * |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
409 ngx_thread_pool_init_conf(ngx_cycle_t *cycle, void *conf) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
410 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
411 ngx_thread_pool_conf_t *tcf = conf; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
412 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
413 ngx_uint_t i; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
414 ngx_thread_pool_t **tpp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
415 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
416 tpp = tcf->pools.elts; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
417 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
418 for (i = 0; i < tcf->pools.nelts; i++) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
419 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
420 if (tpp[i]->threads) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
421 continue; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
422 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
423 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
424 if (tpp[i]->name.len == ngx_thread_pool_default.len |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
425 && ngx_strncmp(tpp[i]->name.data, ngx_thread_pool_default.data, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
426 ngx_thread_pool_default.len) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
427 == 0) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
428 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
429 tpp[i]->threads = 32; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
430 tpp[i]->max_queue = 65536; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
431 continue; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
432 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
433 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
434 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
435 "unknown thread pool \"%V\" in %s:%ui", |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
436 &tpp[i]->name, tpp[i]->file, tpp[i]->line); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
437 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
438 return NGX_CONF_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
439 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
440 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
441 return NGX_CONF_OK; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
442 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
443 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
444 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
445 static char * |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
446 ngx_thread_pool(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
447 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
448 ngx_str_t *value; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
449 ngx_uint_t i; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
450 ngx_thread_pool_t *tp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
451 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
452 value = cf->args->elts; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
453 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
454 tp = ngx_thread_pool_add(cf, &value[1]); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
455 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
456 if (tp == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
457 return NGX_CONF_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
458 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
459 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
460 if (tp->threads) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
461 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
462 "duplicate thread pool \"%V\"", &tp->name); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
463 return NGX_CONF_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
464 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
465 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
466 tp->max_queue = 65536; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
467 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
468 for (i = 2; i < cf->args->nelts; i++) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
469 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
470 if (ngx_strncmp(value[i].data, "threads=", 8) == 0) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
471 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
472 tp->threads = ngx_atoi(value[i].data + 8, value[i].len - 8); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
473 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
474 if (tp->threads == (ngx_uint_t) NGX_ERROR || tp->threads == 0) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
475 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
476 "invalid threads value \"%V\"", &value[i]); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
477 return NGX_CONF_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
478 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
479 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
480 continue; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
481 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
482 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
483 if (ngx_strncmp(value[i].data, "max_queue=", 10) == 0) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
484 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
485 tp->max_queue = ngx_atoi(value[i].data + 10, value[i].len - 10); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
486 |
6026
25fda43e3bcb
Thread pools: fixed the waiting tasks accounting.
Ruslan Ermilov <ru@nginx.com>
parents:
6025
diff
changeset
|
487 if (tp->max_queue == NGX_ERROR) { |
6018
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
488 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
489 "invalid max_queue value \"%V\"", &value[i]); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
490 return NGX_CONF_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
491 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
492 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
493 continue; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
494 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
495 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
496 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
497 if (tp->threads == 0) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
498 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
499 "\"%V\" must have \"threads\" parameter", |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
500 &cmd->name); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
501 return NGX_CONF_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
502 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
503 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
504 return NGX_CONF_OK; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
505 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
506 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
507 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
508 ngx_thread_pool_t * |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
509 ngx_thread_pool_add(ngx_conf_t *cf, ngx_str_t *name) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
510 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
511 ngx_thread_pool_t *tp, **tpp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
512 ngx_thread_pool_conf_t *tcf; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
513 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
514 if (name == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
515 name = &ngx_thread_pool_default; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
516 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
517 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
518 tp = ngx_thread_pool_get(cf->cycle, name); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
519 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
520 if (tp) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
521 return tp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
522 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
523 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
524 tp = ngx_pcalloc(cf->pool, sizeof(ngx_thread_pool_t)); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
525 if (tp == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
526 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
527 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
528 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
529 tp->name = *name; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
530 tp->file = cf->conf_file->file.name.data; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
531 tp->line = cf->conf_file->line; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
532 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
533 tcf = (ngx_thread_pool_conf_t *) ngx_get_conf(cf->cycle->conf_ctx, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
534 ngx_thread_pool_module); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
535 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
536 tpp = ngx_array_push(&tcf->pools); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
537 if (tpp == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
538 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
539 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
540 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
541 *tpp = tp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
542 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
543 return tp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
544 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
545 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
546 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
547 ngx_thread_pool_t * |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
548 ngx_thread_pool_get(ngx_cycle_t *cycle, ngx_str_t *name) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
549 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
550 ngx_uint_t i; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
551 ngx_thread_pool_t **tpp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
552 ngx_thread_pool_conf_t *tcf; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
553 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
554 tcf = (ngx_thread_pool_conf_t *) ngx_get_conf(cycle->conf_ctx, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
555 ngx_thread_pool_module); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
556 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
557 tpp = tcf->pools.elts; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
558 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
559 for (i = 0; i < tcf->pools.nelts; i++) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
560 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
561 if (tpp[i]->name.len == name->len |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
562 && ngx_strncmp(tpp[i]->name.data, name->data, name->len) == 0) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
563 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
564 return tpp[i]; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
565 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
566 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
567 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
568 return NULL; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
569 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
570 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
571 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
572 static ngx_int_t |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
573 ngx_thread_pool_init_worker(ngx_cycle_t *cycle) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
574 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
575 ngx_uint_t i; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
576 ngx_thread_pool_t **tpp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
577 ngx_thread_pool_conf_t *tcf; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
578 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
579 if (ngx_process != NGX_PROCESS_WORKER |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
580 && ngx_process != NGX_PROCESS_SINGLE) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
581 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
582 return NGX_OK; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
583 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
584 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
585 tcf = (ngx_thread_pool_conf_t *) ngx_get_conf(cycle->conf_ctx, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
586 ngx_thread_pool_module); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
587 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
588 if (tcf == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
589 return NGX_OK; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
590 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
591 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
592 if (ngx_thread_pool_queue_init(&ngx_thread_pool_done, cycle->log) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
593 != NGX_OK) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
594 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
595 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
596 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
597 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
598 tpp = tcf->pools.elts; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
599 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
600 for (i = 0; i < tcf->pools.nelts; i++) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
601 if (ngx_thread_pool_init(tpp[i], cycle->log, cycle->pool) != NGX_OK) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
602 return NGX_ERROR; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
603 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
604 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
605 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
606 return NGX_OK; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
607 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
608 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
609 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
610 static void |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
611 ngx_thread_pool_exit_worker(ngx_cycle_t *cycle) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
612 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
613 ngx_uint_t i; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
614 ngx_thread_pool_t **tpp; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
615 ngx_thread_pool_conf_t *tcf; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
616 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
617 if (ngx_process != NGX_PROCESS_WORKER |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
618 && ngx_process != NGX_PROCESS_SINGLE) |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
619 { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
620 return; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
621 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
622 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
623 tcf = (ngx_thread_pool_conf_t *) ngx_get_conf(cycle->conf_ctx, |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
624 ngx_thread_pool_module); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
625 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
626 if (tcf == NULL) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
627 return; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
628 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
629 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
630 tpp = tcf->pools.elts; |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
631 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
632 for (i = 0; i < tcf->pools.nelts; i++) { |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
633 ngx_thread_pool_destroy(tpp[i]); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
634 } |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
635 |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
636 (void) ngx_thread_pool_queue_destroy(&ngx_thread_pool_done, cycle->log); |
466bd63b63d1
Thread pools implementation.
Valentin Bartenev <vbart@nginx.com>
parents:
diff
changeset
|
637 } |