From 283904107fda04abbe4e02cbf3bf01bdd90648cc Mon Sep 17 00:00:00 2001 From: "roberto@goyle" Date: Fri, 24 Jun 2011 06:56:30 +0200 Subject: [PATCH] better master threading --- master.c | 9 ++++++--- plugins/python/gil.c | 2 ++ plugins/python/python_plugin.c | 17 ++++++++--------- uwsgi.h | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/master.c b/master.c index de9b29cc..cea4bfd9 100644 --- a/master.c +++ b/master.c @@ -481,10 +481,13 @@ 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(); - } + if (uwsgi.p[i]->master_fixup) { + uwsgi.p[i]->master_fixup(); + } + } for (;;) { diff --git a/plugins/python/gil.c b/plugins/python/gil.c index 0ee68b01..b84b0233 100644 --- a/plugins/python/gil.c +++ b/plugins/python/gil.c @@ -4,6 +4,7 @@ extern struct uwsgi_server uwsgi; extern struct uwsgi_python up; void gil_real_get() { + uwsgi_log("LOCK %d\n", uwsgi.mywid); #ifndef PYTHREE PyEval_AcquireLock(); PyThreadState_Swap((PyThreadState *) pthread_getspecific(up.upt_gil_key)); @@ -13,6 +14,7 @@ void gil_real_get() { } void gil_real_release() { + uwsgi_log("UNLOCK %d\n", uwsgi.mywid); #ifndef PYTHREE pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Swap(NULL)); PyEval_ReleaseLock(); diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 06416fee..c971565c 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -828,6 +828,13 @@ void uwsgi_python_init_apps() { } +void uwsgi_python_master_fixup() { + + if (uwsgi.has_threads) { + UWSGI_RELEASE_GIL; + } +} + void uwsgi_python_enable_threads() { PyEval_InitThreads(); @@ -853,13 +860,6 @@ void uwsgi_python_enable_threads() { } -void uwsgi_python_master_fixup() { - - if (uwsgi.has_threads) { - UWSGI_RELEASE_GIL; - } -} - void uwsgi_python_init_thread(int core_id) { // set a new ThreadState for each thread @@ -1088,6 +1088,7 @@ struct uwsgi_plugin python_plugin = { .init_apps = uwsgi_python_init_apps, .fixup = uwsgi_python_fixup, + .master_fixup = uwsgi_python_master_fixup, .mount_app = uwsgi_python_mount_app, @@ -1095,8 +1096,6 @@ struct uwsgi_plugin python_plugin = { .init_thread = uwsgi_python_init_thread, .manage_xml = uwsgi_python_xml, - .master_fixup = uwsgi_python_master_fixup, - .magic = uwsgi_python_magic, .suspend = uwsgi_python_suspend, diff --git a/uwsgi.h b/uwsgi.h index d051751d..4b87558f 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -557,7 +557,6 @@ struct uwsgi_plugin { int (*init) (void); void (*post_init) (void); void (*post_fork) (void); - void (*master_fixup) (void); struct option *options; const char *short_options; int (*manage_opt) (int, char *); @@ -567,6 +566,7 @@ struct uwsgi_plugin { void (*after_request) (struct wsgi_request *); void (*init_apps) (void); void (*fixup) (void); + void (*master_fixup) (void); int (*mount_app) (char *, char *); int (*manage_udp) (char *, int, char *, int); int (*manage_xml) (char *, char *);