fixed a stupid deadlock

This commit is contained in:
roberto@precise64
2012-02-17 11:21:08 +01:00
parent 5081a3f635
commit e4711484ac
3 changed files with 15 additions and 10 deletions
+2 -3
View File
@@ -96,12 +96,12 @@ void *logger_thread_loop(void *noarg) {
logpoll.fd = uwsgi.shared->worker_log_pipe[0];
for(;;) {
pthread_mutex_lock(&uwsgi.threaded_logger_lock);
int ret = poll(&logpoll, 1, -1);
if (ret > 0 && logpoll.revents & POLLIN) {
pthread_mutex_lock(&uwsgi.threaded_logger_lock);
master_log();
pthread_mutex_unlock(&uwsgi.threaded_logger_lock);
}
pthread_mutex_unlock(&uwsgi.threaded_logger_lock);
}
return NULL;
@@ -339,7 +339,6 @@ int master_loop(char **argv, char **environ) {
event_queue_add_fd_read(uwsgi.master_queue, uwsgi.shared->worker_log_pipe[0]);
}
else {
pthread_mutex_init(&uwsgi.threaded_logger_lock, NULL);
if (pthread_create(&logger_thread, NULL, logger_thread_loop, NULL)) {
uwsgi_error("pthread_create()");
uwsgi_log("falling back to non-threaded logger...\n");
+6 -6
View File
@@ -113,6 +113,7 @@ int uwsgi_respawn_worker(int wid) {
if (uwsgi.threaded_logger) {
pthread_mutex_lock(&uwsgi.threaded_logger_lock);
}
pid_t pid = uwsgi_fork(uwsgi.workers[wid].name);
if (pid == 0) {
@@ -159,15 +160,9 @@ int uwsgi_respawn_worker(int wid) {
return 1;
}
else if (pid < 1) {
if (uwsgi.threaded_logger) {
pthread_mutex_unlock(&uwsgi.threaded_logger_lock);
}
uwsgi_error("fork()");
}
else {
if (uwsgi.threaded_logger) {
pthread_mutex_unlock(&uwsgi.threaded_logger_lock);
}
if (respawns > 0) {
uwsgi_log("Respawned uWSGI worker %d (new pid: %d)\n", wid, (int) pid);
}
@@ -176,6 +171,11 @@ int uwsgi_respawn_worker(int wid) {
}
}
if (uwsgi.threaded_logger) {
pthread_mutex_unlock(&uwsgi.threaded_logger_lock);
}
return 0;
}
+7 -1
View File
@@ -268,7 +268,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
{"log-syslog", optional_argument, 0, "log to syslog", uwsgi_opt_set_logger, "syslog", UWSGI_OPT_MASTER|UWSGI_OPT_LOG_MASTER},
{"log-socket", required_argument, 0, "send logs to the specified socket", uwsgi_opt_set_logger, "socket", UWSGI_OPT_MASTER|UWSGI_OPT_LOG_MASTER},
{"logger", required_argument, 0, "set logger system", uwsgi_opt_set_logger, NULL, UWSGI_OPT_MASTER|UWSGI_OPT_LOG_MASTER },
{"threaded-logger", no_argument, 0, "offload log writing to a thread", uwsgi_opt_true, &uwsgi.threaded_logger, 0},
{"threaded-logger", no_argument, 0, "offload log writing to a thread", uwsgi_opt_true, &uwsgi.threaded_logger, UWSGI_OPT_MASTER|UWSGI_OPT_LOG_MASTER},
#ifdef UWSGI_ZEROMQ
{"log-zeromq", required_argument, 0, "send logs to a zeromq server", uwsgi_opt_set_logger, "zeromq", UWSGI_OPT_MASTER|UWSGI_OPT_LOG_MASTER},
#endif
@@ -2524,6 +2524,11 @@ skipzero:
#endif
if (uwsgi.master_process) {
// initialize a mutex to avoid glibc problem with pthread+fork()
if (uwsgi.threaded_logger) {
pthread_mutex_init(&uwsgi.threaded_logger_lock, NULL);
}
if (uwsgi.is_a_reload) {
uwsgi_log("gracefully (RE)spawned uWSGI master process (pid: %d)\n", uwsgi.mypid);
}
@@ -2565,6 +2570,7 @@ skipzero:
}
#endif
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);