add pthread locking for init_uwsgi_app

This commit is contained in:
roberto@sirius
2010-10-12 07:59:37 +02:00
parent 6d9b753735
commit 85752ccf2c
5 changed files with 23 additions and 3 deletions
+1 -1
View File
@@ -259,7 +259,7 @@ int uwsgi_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
return -1;
}
if (uwsgi_parse_vars(uwsgi, wsgi_req)) {
if (uwsgi_parse_vars(wsgi_req)) {
uwsgi_log("Invalid RACK request. skip.\n");
return -1;
}
+3 -2
View File
@@ -1,5 +1,6 @@
import os,sys
NAME='rack'
CFLAGS = '-I' + os.popen("ruby -e \"require 'mkmf';print Config::CONFIG['archdir']\"").read().rstrip()
LDFLAGS = '-l' + os.popen("ruby -e \"require 'mkmf';print CONFIG['RUBY_SO_NAME']\"").read().rstrip()
#CFLAGS = '-I' + os.popen("/Users/roberto/RUBY/bin/ruby -e \"require 'mkmf';print Config::CONFIG['archdir']\"").read().rstrip()
CFLAGS = '-I/Users/roberto/RUBY//include/ruby-1.9.1 -DHAVE_STRUCT_TIMESPEC -DHAVE_STRUCT_TIMEZONE'
LDFLAGS = '-l' + os.popen("/Users/roberto/RUBY/bin/ruby -e \"require 'mkmf';print CONFIG['RUBY_SO_NAME']\"").read().rstrip()
+13
View File
@@ -34,6 +34,10 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, int ne
struct uwsgi_app *wi;
if (uwsgi.threads > 1) {
pthread_mutex_lock(&uwsgi.lock_pyloaders);
}
if (wsgi_req->script_name_len == 0) {
wsgi_req->script_name = "";
if (!uwsgi.vhost) id = 0;
@@ -55,6 +59,9 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, int ne
if (uwsgi_get_app_id(mountpoint, strlen(mountpoint)) != -1) {
uwsgi_log( "mountpoint %.*s already configured. skip.\n", strlen(mountpoint), mountpoint);
free(mountpoint);
if (uwsgi.threads > 1) {
pthread_mutex_unlock(&uwsgi.lock_pyloaders);
}
return -1;
}
@@ -251,6 +258,9 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, int ne
}
uwsgi_log("\n");
if (uwsgi.threads > 1) {
pthread_mutex_unlock(&uwsgi.lock_pyloaders);
}
return id;
@@ -266,6 +276,9 @@ doh:
PyThreadState_Swap(uwsgi.main_thread);
}
}
if (uwsgi.threads > 1) {
pthread_mutex_unlock(&uwsgi.lock_pyloaders);
}
return -1;
}
+2
View File
@@ -969,6 +969,8 @@ int main(int argc, char *argv[], char *envp[]) {
exit(1);
}
pthread_setspecific(uwsgi.ut_save_key, (void *) PyThreadState_Get());
// initialize the mutexes
pthread_mutex_init(&uwsgi.lock_pyloaders, NULL);
uwsgi.gil_get = gil_real_get;
uwsgi.gil_release = gil_real_release;
uwsgi.current_wsgi_req = threaded_current_wsgi_req;
+4
View File
@@ -807,6 +807,10 @@ struct uwsgi_server {
struct wsgi_request* (*current_wsgi_req)(void);
int close_on_exec;
#ifdef UWSGI_THREADING
pthread_mutex_t lock_pyloaders;
#endif
};
struct uwsgi_cluster_node {