From f3d02cb9e260cee88cbfa9d495c0a937644768f4 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Wed, 6 Jun 2018 22:53:15 -0400 Subject: wsd: support polling on client thread Previously SocketPoll expected to be running its own thread for polling. This is unnecessary when we have a spare thread (e.g. main) that can (and should, for efficiency) be used for polling rather than starting dedicated thread. Not starting the SocketPoll's thread and calling SocketPoll::poll() directly worked, the warning logs on each activity notwithstanding. The warnings aren't just noisy, they are a performance drain as well, and signal that something is wrong. The new code now makes the API cleaner and avoids unnecessary warning logs, while being faster. Change-Id: Ibf9a223c59dae6522a5fc2e5d84a8ef191b577b1 --- net/Socket.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'net/Socket.cpp') diff --git a/net/Socket.cpp b/net/Socket.cpp index 8acd98ba22..208efc3c9c 100644 --- a/net/Socket.cpp +++ b/net/Socket.cpp @@ -66,6 +66,7 @@ SocketPoll::SocketPoll(const std::string& threadName) _stop(false), _threadStarted(false), _threadFinished(false), + _runOnClientThread(false), _owner(std::this_thread::get_id()) { // Create the wakeup fd. @@ -109,8 +110,10 @@ SocketPoll::~SocketPoll() _wakeup[1] = -1; } -void SocketPoll::startThread() +bool SocketPoll::startThread() { + assert(!_runOnClientThread); + if (!_threadStarted) { _threadStarted = true; @@ -119,6 +122,7 @@ void SocketPoll::startThread() try { _thread = std::thread(&SocketPoll::pollingThreadEntry, this); + return true; } catch (const std::exception& exc) { @@ -126,6 +130,8 @@ void SocketPoll::startThread() _threadStarted = false; } } + + return false; } void SocketPoll::joinThread() -- cgit