Mercurial > hg > nginx
comparison src/os/unix/ngx_process_cycle.c @ 6029:e284f3ff6831
Removed old pthread implementation.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 20 Mar 2015 06:43:19 +0300 |
parents | 457ec43dd8d5 |
children | 4652f8f26b12 |
comparison
equal
deleted
inserted
replaced
6028:fa77496b1df2 | 6029:e284f3ff6831 |
---|---|
21 static void ngx_master_process_exit(ngx_cycle_t *cycle); | 21 static void ngx_master_process_exit(ngx_cycle_t *cycle); |
22 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); | 22 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
23 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker); | 23 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker); |
24 static void ngx_worker_process_exit(ngx_cycle_t *cycle); | 24 static void ngx_worker_process_exit(ngx_cycle_t *cycle); |
25 static void ngx_channel_handler(ngx_event_t *ev); | 25 static void ngx_channel_handler(ngx_event_t *ev); |
26 #if (NGX_OLD_THREADS) | |
27 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); | |
28 static ngx_thread_value_t ngx_worker_thread_cycle(void *data); | |
29 #endif | |
30 static void ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data); | 26 static void ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data); |
31 static void ngx_cache_manager_process_handler(ngx_event_t *ev); | 27 static void ngx_cache_manager_process_handler(ngx_event_t *ev); |
32 static void ngx_cache_loader_process_handler(ngx_event_t *ev); | 28 static void ngx_cache_loader_process_handler(ngx_event_t *ev); |
33 | 29 |
34 | 30 |
52 ngx_uint_t ngx_daemonized; | 48 ngx_uint_t ngx_daemonized; |
53 | 49 |
54 sig_atomic_t ngx_noaccept; | 50 sig_atomic_t ngx_noaccept; |
55 ngx_uint_t ngx_noaccepting; | 51 ngx_uint_t ngx_noaccepting; |
56 ngx_uint_t ngx_restart; | 52 ngx_uint_t ngx_restart; |
57 | |
58 | |
59 #if (NGX_OLD_THREADS) | |
60 volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS]; | |
61 ngx_int_t ngx_threads_n; | |
62 #endif | |
63 | 53 |
64 | 54 |
65 static u_char master_process[] = "master process"; | 55 static u_char master_process[] = "master process"; |
66 | 56 |
67 | 57 |
745 | 735 |
746 ngx_worker_process_init(cycle, worker); | 736 ngx_worker_process_init(cycle, worker); |
747 | 737 |
748 ngx_setproctitle("worker process"); | 738 ngx_setproctitle("worker process"); |
749 | 739 |
750 #if (NGX_OLD_THREADS) | |
751 { | |
752 ngx_int_t n; | |
753 ngx_err_t err; | |
754 ngx_core_conf_t *ccf; | |
755 | |
756 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
757 | |
758 if (ngx_threads_n) { | |
759 if (ngx_init_threads(ngx_threads_n, ccf->thread_stack_size, cycle) | |
760 == NGX_ERROR) | |
761 { | |
762 /* fatal */ | |
763 exit(2); | |
764 } | |
765 | |
766 err = ngx_thread_key_create(&ngx_core_tls_key); | |
767 if (err != 0) { | |
768 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
769 ngx_thread_key_create_n " failed"); | |
770 /* fatal */ | |
771 exit(2); | |
772 } | |
773 | |
774 for (n = 0; n < ngx_threads_n; n++) { | |
775 | |
776 ngx_threads[n].cv = ngx_cond_init(cycle->log); | |
777 | |
778 if (ngx_threads[n].cv == NULL) { | |
779 /* fatal */ | |
780 exit(2); | |
781 } | |
782 | |
783 if (ngx_create_thread((ngx_tid_t *) &ngx_threads[n].tid, | |
784 ngx_worker_thread_cycle, | |
785 (void *) &ngx_threads[n], cycle->log) | |
786 != 0) | |
787 { | |
788 /* fatal */ | |
789 exit(2); | |
790 } | |
791 } | |
792 } | |
793 } | |
794 #endif | |
795 | |
796 for ( ;; ) { | 740 for ( ;; ) { |
797 | 741 |
798 if (ngx_exiting) { | 742 if (ngx_exiting) { |
799 | 743 |
800 c = cycle->connections; | 744 c = cycle->connections; |
1029 static void | 973 static void |
1030 ngx_worker_process_exit(ngx_cycle_t *cycle) | 974 ngx_worker_process_exit(ngx_cycle_t *cycle) |
1031 { | 975 { |
1032 ngx_uint_t i; | 976 ngx_uint_t i; |
1033 ngx_connection_t *c; | 977 ngx_connection_t *c; |
1034 | |
1035 #if (NGX_OLD_THREADS) | |
1036 ngx_terminate = 1; | |
1037 | |
1038 ngx_wakeup_worker_threads(cycle); | |
1039 #endif | |
1040 | 978 |
1041 for (i = 0; ngx_modules[i]; i++) { | 979 for (i = 0; ngx_modules[i]; i++) { |
1042 if (ngx_modules[i]->exit_process) { | 980 if (ngx_modules[i]->exit_process) { |
1043 ngx_modules[i]->exit_process(cycle); | 981 ngx_modules[i]->exit_process(cycle); |
1044 } | 982 } |
1179 } | 1117 } |
1180 } | 1118 } |
1181 } | 1119 } |
1182 | 1120 |
1183 | 1121 |
1184 #if (NGX_OLD_THREADS) | |
1185 | |
1186 static void | |
1187 ngx_wakeup_worker_threads(ngx_cycle_t *cycle) | |
1188 { | |
1189 ngx_int_t i; | |
1190 ngx_uint_t live; | |
1191 | |
1192 for ( ;; ) { | |
1193 | |
1194 live = 0; | |
1195 | |
1196 for (i = 0; i < ngx_threads_n; i++) { | |
1197 if (ngx_threads[i].state < NGX_THREAD_EXIT) { | |
1198 if (ngx_cond_signal(ngx_threads[i].cv) == NGX_ERROR) { | |
1199 ngx_threads[i].state = NGX_THREAD_DONE; | |
1200 | |
1201 } else { | |
1202 live = 1; | |
1203 } | |
1204 } | |
1205 | |
1206 if (ngx_threads[i].state == NGX_THREAD_EXIT) { | |
1207 ngx_thread_join(ngx_threads[i].tid, NULL); | |
1208 ngx_threads[i].state = NGX_THREAD_DONE; | |
1209 } | |
1210 } | |
1211 | |
1212 if (live == 0) { | |
1213 ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
1214 "all worker threads are joined"); | |
1215 | |
1216 /* STUB */ | |
1217 ngx_done_events(cycle); | |
1218 | |
1219 return; | |
1220 } | |
1221 | |
1222 ngx_sched_yield(); | |
1223 } | |
1224 } | |
1225 | |
1226 | |
1227 static ngx_thread_value_t | |
1228 ngx_worker_thread_cycle(void *data) | |
1229 { | |
1230 ngx_thread_t *thr = data; | |
1231 | |
1232 sigset_t set; | |
1233 ngx_err_t err; | |
1234 ngx_core_tls_t *tls; | |
1235 ngx_cycle_t *cycle; | |
1236 | |
1237 cycle = (ngx_cycle_t *) ngx_cycle; | |
1238 | |
1239 sigemptyset(&set); | |
1240 sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL)); | |
1241 sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL)); | |
1242 sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL)); | |
1243 | |
1244 err = ngx_thread_sigmask(SIG_BLOCK, &set, NULL); | |
1245 if (err) { | |
1246 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
1247 ngx_thread_sigmask_n " failed"); | |
1248 return (ngx_thread_value_t) 1; | |
1249 } | |
1250 | |
1251 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
1252 "thread " NGX_TID_T_FMT " started", ngx_thread_self()); | |
1253 | |
1254 ngx_setthrtitle("worker thread"); | |
1255 | |
1256 tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log); | |
1257 if (tls == NULL) { | |
1258 return (ngx_thread_value_t) 1; | |
1259 } | |
1260 | |
1261 err = ngx_thread_set_tls(ngx_core_tls_key, tls); | |
1262 if (err != 0) { | |
1263 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
1264 ngx_thread_set_tls_n " failed"); | |
1265 return (ngx_thread_value_t) 1; | |
1266 } | |
1267 | |
1268 for ( ;; ) { | |
1269 thr->state = NGX_THREAD_FREE; | |
1270 | |
1271 #if 0 | |
1272 if (ngx_cond_wait(thr->cv, ngx_posted_events_mutex) == NGX_ERROR) { | |
1273 return (ngx_thread_value_t) 1; | |
1274 } | |
1275 #endif | |
1276 | |
1277 if (ngx_terminate) { | |
1278 thr->state = NGX_THREAD_EXIT; | |
1279 | |
1280 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
1281 "thread " NGX_TID_T_FMT " is done", | |
1282 ngx_thread_self()); | |
1283 | |
1284 return (ngx_thread_value_t) 0; | |
1285 } | |
1286 | |
1287 thr->state = NGX_THREAD_BUSY; | |
1288 | |
1289 #if 0 | |
1290 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { | |
1291 return (ngx_thread_value_t) 1; | |
1292 } | |
1293 | |
1294 if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { | |
1295 return (ngx_thread_value_t) 1; | |
1296 } | |
1297 #endif | |
1298 | |
1299 if (ngx_process_changes) { | |
1300 if (ngx_process_changes(cycle, 1) == NGX_ERROR) { | |
1301 return (ngx_thread_value_t) 1; | |
1302 } | |
1303 } | |
1304 } | |
1305 } | |
1306 | |
1307 #endif | |
1308 | |
1309 | |
1310 static void | 1122 static void |
1311 ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data) | 1123 ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data) |
1312 { | 1124 { |
1313 ngx_cache_manager_ctx_t *ctx = data; | 1125 ngx_cache_manager_ctx_t *ctx = data; |
1314 | 1126 |