summaryrefslogtreecommitdiffstats
path: root/net/Socket.cpp
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-06 22:53:15 -0400
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-10-16 20:12:23 -0400
commitf3d02cb9e260cee88cbfa9d495c0a937644768f4 (patch)
tree36abc29c2dceac44a96dce3c475b2995086c33cd /net/Socket.cpp
parentwsd: always use signal-safe calls (diff)
downloadonline-f3d02cb9e260cee88cbfa9d495c0a937644768f4.tar.gz
online-f3d02cb9e260cee88cbfa9d495c0a937644768f4.zip
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
Diffstat (limited to 'net/Socket.cpp')
-rw-r--r--net/Socket.cpp8
1 files changed, 7 insertions, 1 deletions
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()