From a05f5d98605cb9a4fafeddb9f767de9fe5e708e7 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Sat, 25 Jun 2011 09:36:59 +0200 Subject: [PATCH] another series (the last i hope) of threading fixes --- master.c | 9 --------- plugins/python/gil.c | 2 ++ plugins/python/python_plugin.c | 15 +++++++++++++-- uwsgi.c | 11 ++++++++++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/master.c b/master.c index 42fff007..ad2c2dda 100644 --- a/master.c +++ b/master.c @@ -481,15 +481,6 @@ void master_loop(char **argv, char **environ) { } } - // fixup - - for (i = 0; i < 0xFF; i++) { - if (uwsgi.p[i]->master_fixup) { - uwsgi.p[i]->master_fixup(0); - } - } - - for (;;) { //uwsgi_log("ready_to_reload %d %d\n", ready_to_reload, uwsgi.numproc); diff --git a/plugins/python/gil.c b/plugins/python/gil.c index a1f4544f..02ec6986 100644 --- a/plugins/python/gil.c +++ b/plugins/python/gil.c @@ -11,6 +11,8 @@ void gil_real_get() { #else PyEval_RestoreThread((PyThreadState *) pthread_getspecific(up.upt_gil_key)); #endif + + //uwsgi_log("LOCKED !!! %d\n", uwsgi.mywid); } void gil_real_release() { diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index d05f35be..b60b3174 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -830,12 +830,23 @@ void uwsgi_python_init_apps() { void uwsgi_python_master_fixup(int step) { + static int master_fixed = 0; + static int worker_fixed = 0; + + if (!uwsgi.master_process) return; + if (uwsgi.has_threads) { if (step == 0) { - UWSGI_RELEASE_GIL; + if (!master_fixed) { + UWSGI_RELEASE_GIL; + master_fixed = 1; + } } else { - UWSGI_GET_GIL; + if (!worker_fixed) { + UWSGI_GET_GIL; + worker_fixed = 1; + } } } } diff --git a/uwsgi.c b/uwsgi.c index 14d3342d..70d963fe 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1978,7 +1978,6 @@ int uwsgi_start(void *v_argv) { } - //init apps hook (if not lazy) if (!uwsgi.lazy) { uwsgi_init_all_apps(); @@ -2029,6 +2028,15 @@ int uwsgi_start(void *v_argv) { routing_setup(); #endif + // master fixup + + for (i = 0; i < 0xFF; i++) { + if (uwsgi.p[i]->master_fixup) { + uwsgi.p[i]->master_fixup(0); + } + } + + if (!uwsgi.master_process) { if (uwsgi.numproc == 1) { uwsgi_log("spawned uWSGI worker 1 (and the only) (pid: %d, cores: %d)\n", masterpid, uwsgi.cores); @@ -2435,6 +2443,7 @@ void uwsgi_ignition() { #else if (uwsgi.threads > 1) { #endif + if (pthread_key_create(&uwsgi.tur_key, NULL)) { uwsgi_error("pthread_key_create()"); exit(1);