]> git.sesse.net Git - cubemap/blobdiff - server.cpp
Reinstate the new signal handling; revert the revert.
[cubemap] / server.cpp
index a0a32f8e704a716cad99563cd75b4bc47cfeb41b..6d5cce372ae9c79b81b4b755052252680ce3cf28 100644 (file)
@@ -72,8 +72,14 @@ void Server::do_work()
 {
        while (!should_stop()) {
                // Wait until there's activity on at least one of the fds,
-               // or we are waken up due to new queued clients or data.
-               int nfds = epoll_pwait(epoll_fd, events, EPOLL_MAX_EVENTS, -1, &sigset_without_usr1_block);
+               // or 20 ms (about one frame at 50 fps) has elapsed.
+               //
+               // We could in theory wait forever and rely on wakeup()
+               // from add_client_deferred() and add_data_deferred(),
+               // but wakeup is a pretty expensive operation, and the
+               // two threads might end up fighting over a lock, so it's
+               // seemingly (much) more efficient to just have a timeout here.
+               int nfds = epoll_pwait(epoll_fd, events, EPOLL_MAX_EVENTS, EPOLL_TIMEOUT_MS, &sigset_without_usr1_block);
                if (nfds == -1 && errno != EINTR) {
                        log_perror("epoll_wait");
                        exit(1);
@@ -129,7 +135,6 @@ void Server::add_client_deferred(int sock)
 {
        MutexLock lock(&queued_data_mutex);
        queued_add_clients.push_back(sock);
-       wakeup();
 }
 
 void Server::add_client(int sock)
@@ -246,7 +251,6 @@ void Server::add_data_deferred(const string &stream_id, const char *data, size_t
 {
        MutexLock lock(&queued_data_mutex);
        queued_data[stream_id].append(string(data, data + bytes));
-       wakeup();
 }
 
 // See the .h file for postconditions after this function.