From 9d405c6cb234e3807af8f464677c6587c41344dd Mon Sep 17 00:00:00 2001 From: "roberto@mrspurr" Date: Fri, 6 Apr 2012 10:28:02 +0200 Subject: [PATCH] fixed locking in uwsgi.cache_exists --- plugins/python/uwsgi_pymodule.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 69050499..8ca132c0 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -3253,15 +3253,25 @@ PyObject *py_uwsgi_cache_exists(PyObject * self, PyObject * args) { if (remote && strlen(remote) > 0) { // TODO FIX THIS !!! + UWSGI_RELEASE_GIL uwsgi_simple_message_string(remote, 111, 0, key, keylen, buffer, &valsize, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + UWSGI_GET_GIL if (valsize > 0) { Py_INCREF(Py_True); return Py_True; } } - else if (uwsgi_cache_exists(key, keylen)) { - Py_INCREF(Py_True); - return Py_True; + else if (uwsgi.cache_max_items) { + UWSGI_RELEASE_GIL + uwsgi_rlock(uwsgi.cache_lock); + if (uwsgi_cache_exists(key, keylen)) { + uwsgi_rwunlock(uwsgi.cache_lock); + UWSGI_GET_GIL + Py_INCREF(Py_True); + return Py_True; + } + uwsgi_rwunlock(uwsgi.cache_lock); + UWSGI_GET_GIL } Py_INCREF(Py_None);