unipoll: allow LOK's Yield callback to be called from any thread.

Change-Id: I1ab46135919a1f06f814cc8702991592c84d28a7
Reviewed-on: https://gerrit.libreoffice.org/73752
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:
Michael Meeks
2019-06-10 11:17:02 +01:00
parent f94a00ddc9
commit 579c827363

View File

@ -473,12 +473,30 @@ public:
assert(_stop || sameThread);
}
/// Kit poll can be called from LOK's Yield in any thread, adapt to that.
void checkAndReThread()
{
if (InhibitThreadChecks)
return;
std::thread::id us = std::thread::id();
if (_owner == us)
return; // all well
LOG_DBG("Ununusual - SocketPoll used from a new thread");
_owner = us;
for (auto it : _pollSockets)
it->setThreadOwner(us);
// _newSockets are adapted as they are inserted.
}
/// Poll the sockets for available data to read or buffer to write.
/// Returns the return-value of poll(2): 0 on timeout,
/// -1 for error, and otherwise the number of events signalled.
int poll(int timeoutMaxMs)
{
assertCorrectThread();
if (_runOnClientThread)
checkAndReThread();
else
assertCorrectThread();
std::chrono::steady_clock::time_point now =
std::chrono::steady_clock::now();