From 26b7e6aabf24e3f688a72673f74b00cb238c2bea Mon Sep 17 00:00:00 2001 From: "roberto@sirius" Date: Mon, 14 May 2012 17:42:34 +0200 Subject: [PATCH] improved wait_for_threads --- plugins/python/uwsgi_pymodule.c | 4 +++- uwsgi.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index e2fd0ddc..0fe1ce39 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -709,7 +709,9 @@ PyObject *py_uwsgi_send(PyObject * self, PyObject * args) { PyObject *data; PyObject *arg1, *arg2; - int uwsgi_fd = uwsgi.wsgi_req->poll.fd; + struct wsgi_request *wsgi_req = current_wsgi_req(); + + int uwsgi_fd = wsgi_req->poll.fd; if (!PyArg_ParseTuple(args, "O|O:send", &arg1, &arg2)) { return NULL; diff --git a/uwsgi.c b/uwsgi.c index 77c01895..c026122f 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -541,13 +541,20 @@ void warn_pipe() { void wait_for_threads() { int i, ret; + int sudden_death = 0; + pthread_mutex_lock(&uwsgi.six_feet_under_lock); for (i = 0; i < uwsgi.threads; i++) { if (!pthread_equal(uwsgi.core[i]->thread_id, pthread_self())) { - pthread_cancel(uwsgi.core[i]->thread_id); + if (pthread_cancel(uwsgi.core[i]->thread_id)) { + uwsgi_error("pthread_cancel()\n"); + sudden_death = 1; + } } } + if (sudden_death) goto end; + // wait for thread termination for (i = 0; i < uwsgi.threads; i++) { if (!pthread_equal(uwsgi.core[i]->thread_id, pthread_self())) { @@ -558,6 +565,8 @@ void wait_for_threads() { } } +end: + pthread_mutex_unlock(&uwsgi.six_feet_under_lock); } #endif