X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=server.cpp;h=6d5cce372ae9c79b81b4b755052252680ce3cf28;hb=5179ad190827a75ee096f2cc92d3f0d8837eff72;hp=a0a32f8e704a716cad99563cd75b4bc47cfeb41b;hpb=3fd8650ccf3da3960a946d8ac9abc305aec399ce;p=cubemap diff --git a/server.cpp b/server.cpp index a0a32f8..6d5cce3 100644 --- a/server.cpp +++ b/server.cpp @@ -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.