Skip to content

Commit

Permalink
thunder_lock enabled only in threading mode
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@dexter committed Jul 15, 2011
1 parent a1ab298 commit c4664fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 5 additions & 5 deletions utils.c
Expand Up @@ -768,10 +768,10 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) {
char uwsgi_signal;
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;

uwsgi_lock(uwsgi.thunder_lock);
thunder_lock;
ret = event_queue_wait(queue, uwsgi.edge_triggered - 1, &interesting_fd);
if (ret < 0) {
uwsgi_unlock(uwsgi.thunder_lock);
thunder_unlock;
return -1;
}

Expand All @@ -782,7 +782,7 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) {

if (uwsgi.signal_socket > -1 && (interesting_fd == uwsgi.signal_socket || interesting_fd == uwsgi.my_signal_socket)) {

uwsgi_unlock(uwsgi.thunder_lock);
thunder_unlock;

if (read(interesting_fd, &uwsgi_signal, 1) <= 0) {
if (uwsgi.no_orphans) {
Expand Down Expand Up @@ -813,7 +813,7 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) {
if (interesting_fd == uwsgi_sock->fd || (uwsgi.edge_triggered && uwsgi_sock->edge_trigger)) {
wsgi_req->socket = uwsgi_sock;
wsgi_req->poll.fd = wsgi_req->socket->proto_accept(wsgi_req, interesting_fd);
uwsgi_unlock(uwsgi.thunder_lock);
thunder_unlock;
if (wsgi_req->poll.fd < 0) {
#ifdef UWSGI_THREADING
if (uwsgi.threads > 1) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ret);
Expand Down Expand Up @@ -848,7 +848,7 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) {
uwsgi_sock = uwsgi_sock->next;
}

uwsgi_unlock(uwsgi.thunder_lock);
thunder_unlock;
#ifdef UWSGI_THREADING
if (uwsgi.threads > 1) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ret);
#endif
Expand Down
7 changes: 4 additions & 3 deletions uwsgi.c
Expand Up @@ -1564,9 +1564,10 @@ int uwsgi_start(void *v_argv) {
}


// event queue lock (avoid same oevent on multiple queues)
uwsgi.thunder_lock = uwsgi_mmap_shared_lock();
uwsgi_lock_init(uwsgi.thunder_lock);
// event queue lock (mitigate same event on multiple queues)
if (uwsgi.threads > 1) {
pthread_mutex_init(&uwsgi.thunder_mutex, NULL);
}

// application generic lock
uwsgi.user_lock = uwsgi_mmap_shared_lock();
Expand Down
5 changes: 4 additions & 1 deletion uwsgi.h
Expand Up @@ -19,6 +19,9 @@ extern "C" {

#define wsgi_req_time ((wsgi_req->end_of_request.tv_sec * 1000000 + wsgi_req->end_of_request.tv_usec) - (wsgi_req->start_of_request.tv_sec * 1000000 + wsgi_req->start_of_request.tv_usec))/1000

#define thunder_lock if (uwsgi.threads > 1) {pthread_mutex_lock(&uwsgi.thunder_mutex);}
#define thunder_unlock if (uwsgi.threads > 1) {pthread_mutex_unlock(&uwsgi.thunder_mutex);}

#define ushared uwsgi.shared

#define MAX_APPS 64
Expand Down Expand Up @@ -1260,7 +1263,7 @@ struct uwsgi_server {
size_t queue_filesize;
int queue_store_sync;

void *thunder_lock;
pthread_mutex_t thunder_mutex;

void *cache_lock;
void *queue_lock;
Expand Down

0 comments on commit c4664fe

Please sign in to comment.