]> git.sesse.net Git - cubemap/commitdiff
Explicitly SIGHUP threads to kill them out of syscalls when we want to join them...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 9 Apr 2013 20:37:55 +0000 (22:37 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 9 Apr 2013 20:37:55 +0000 (22:37 +0200)
input.cpp
main.cpp
server.cpp

index 47c3c0193472d8cfa56747fd2461cdf5595632cd..ccc4bc0134e47870ae5e44f7f5c9210d897260bd 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -11,6 +11,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <poll.h>
+#include <signal.h>
 #include <errno.h>
 #include <vector>
 #include <string>
@@ -128,6 +129,7 @@ void Input::stop()
 {
        should_stop = true;
 
+       pthread_kill(worker_thread, SIGHUP);
        if (pthread_join(worker_thread, NULL) == -1) {
                perror("pthread_join");
                exit(1);
@@ -269,7 +271,7 @@ void Input::do_work()
                        pfd.events |= POLLRDHUP;
 
                        int nfds = poll(&pfd, 1, 50);
-                       if (nfds == 0 || (nfds == -1 && errno == EAGAIN)) {
+                       if (nfds == 0 || (nfds == -1 && errno == EINTR)) {
                                continue;
                        }
                        if (nfds == -1) {
index 2af1996fe670d7152c81552e00018f17052f3aac..0564e27e8a2a865e1ea9e0f62cf7bc622c27c5d4 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -94,7 +94,7 @@ void *acceptor_thread_run(void *arg)
                pfd.events = POLLIN;
 
                int nfds = poll(&pfd, 1, 50);
-               if (nfds == 0 || (nfds == -1 && errno == EAGAIN)) {
+               if (nfds == 0 || (nfds == -1 && errno == EINTR)) {
                        continue;
                }
                if (nfds == -1) {
@@ -187,7 +187,7 @@ sleep:
                int left_to_sleep = parms->stats_interval;
                do {
                        left_to_sleep = sleep(left_to_sleep);
-               } while (left_to_sleep > 0);
+               } while (left_to_sleep > 0 && !hupped);
        }
        return NULL;
 }
@@ -433,11 +433,13 @@ int main(int argc, char **argv)
        gettimeofday(&serialize_start, NULL);
 
        if (!stats_file.empty()) {
+               pthread_kill(stats_thread, SIGHUP);
                if (pthread_join(stats_thread, NULL) == -1) {
                        perror("pthread_join");
                        exit(1);
                }
        }
+       pthread_kill(acceptor_thread, SIGHUP);
        if (pthread_join(acceptor_thread, NULL) == -1) {
                perror("pthread_join");
                exit(1);
index 5c55636668eca819141f44099461ae419c51d997..6e1005e1090ccd851c5690f3f6f4174c6c00f8ab 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/ioctl.h>
 #include <sys/epoll.h>
 #include <time.h>
+#include <signal.h>
 #include <errno.h>
 #include <vector>
 #include <string>
@@ -180,6 +181,7 @@ void Server::stop()
                should_stop = true;
        }
 
+       pthread_kill(worker_thread, SIGHUP);
        if (pthread_join(worker_thread, NULL) == -1) {
                perror("pthread_join");
                exit(1);
@@ -211,6 +213,9 @@ void Server::do_work()
        for ( ;; ) {
                int nfds = epoll_wait(epoll_fd, events, EPOLL_MAX_EVENTS, EPOLL_TIMEOUT_MS);
                if (nfds == -1 && errno == EINTR) {
+                       if (should_stop) {
+                               return;
+                       }
                        continue;
                }
                if (nfds == -1) {
@@ -220,10 +225,6 @@ void Server::do_work()
 
                MutexLock lock(&mutex);  // We release the mutex between iterations.
        
-               if (should_stop) {
-                       return;
-               }
-
                process_queued_data();
 
                for (int i = 0; i < nfds; ++i) {
@@ -248,6 +249,10 @@ void Server::do_work()
                                process_client(to_process[i]);
                        }
                }
+
+               if (should_stop) {
+                       return;
+               }
        }
 }