]> git.sesse.net Git - cubemap/commitdiff
Fix so clients would actually be woken up from the worker thread, not the input threa...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 7 Apr 2013 21:26:37 +0000 (23:26 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 7 Apr 2013 21:26:37 +0000 (23:26 +0200)
server.cpp
server.h

index eeab64bb64fbf7bb790d89b14150e4eb97f42251..d41e3c70730b896e44a9362bf150ae534ee9f892 100644 (file)
@@ -162,7 +162,7 @@ void Server::do_work()
                if (should_stop) {
                        return;
                }
                if (should_stop) {
                        return;
                }
-       
+
                for (int i = 0; i < nfds; ++i) {
                        int fd = events[i].data.fd;
                        assert(clients.count(fd) != 0);
                for (int i = 0; i < nfds; ++i) {
                        int fd = events[i].data.fd;
                        assert(clients.count(fd) != 0);
@@ -175,6 +175,11 @@ void Server::do_work()
 
                        process_client(client);
                }
 
                        process_client(client);
                }
+
+               for (unsigned i = 0; i < to_process.size(); ++i) {
+                       process_client(to_process[i]);
+               }
+               to_process.clear();
        }
 }
 
        }
 }
 
@@ -579,10 +584,11 @@ void Server::put_client_to_sleep(Client *client)
 
 void Server::wake_up_all_clients()
 {
 
 void Server::wake_up_all_clients()
 {
-       vector<Client *> to_process;
-       swap(sleeping_clients, to_process);
-       for (unsigned i = 0; i < to_process.size(); ++i) {
-               process_client(to_process[i]);
+       if (to_process.empty()) {
+               swap(sleeping_clients, to_process);
+       } else {
+               to_process.insert(to_process.end(), sleeping_clients.begin(), sleeping_clients.end());
+               sleeping_clients.clear();
        }
 }
        
        }
 }
        
index fd309f41e34e1b97434f5af0071f9a47e4ad6690..6e0dd9dac2fd98f48d2a7fc24def92b5eee064cd 100644 (file)
--- a/server.h
+++ b/server.h
@@ -124,6 +124,10 @@ private:
        // See put_client_to_sleep() and wake_up_all_clients().
        std::vector<Client *> sleeping_clients;
 
        // See put_client_to_sleep() and wake_up_all_clients().
        std::vector<Client *> sleeping_clients;
 
+       // Clients that we recently got data for (when they were in
+       // <sleeping_clients>).
+       std::vector<Client *> to_process;
+
        // Recover the this pointer, and call do_work().
        static void *do_work_thunk(void *arg);
 
        // Recover the this pointer, and call do_work().
        static void *do_work_thunk(void *arg);