wsd: mark detached sockets to have no owner

The DocBroker might not get a chance to
take ownership of a socket (which is done
via callbacks that are invoked in the poll loop)
if it (or WSD) is flagged for termination.

In that case, DocBroker doesn't take ownership
but ultimately needs to disconnect the socket.

By detaching ownership we signal that any thread
can rightly take ownership and thus avoid spurious
warning or assertions.

Change-Id: Idb192bfaac05c5c86809cb21876f3926a080b775
Reviewed-on: https://gerrit.libreoffice.org/36117
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
Ashod Nakashian 2017-04-05 00:26:31 -04:00 committed by Ashod Nakashian
parent 2254b71682
commit 463f26f417

View file

@ -198,7 +198,8 @@ public:
virtual bool isCorrectThread()
{
#if ENABLE_DEBUG
const bool sameThread = std::this_thread::get_id() == _owner;
// 0 owner means detached and can be invoked by any thread.
const bool sameThread = (_owner == std::thread::id(0) || std::this_thread::get_id() == _owner);
if (!sameThread)
LOG_WRN("#" << _fd << " Invoked from foreign thread. Expected: 0x" << std::hex <<
_owner << " but called from 0x" << std::this_thread::get_id() << " (" <<
@ -294,12 +295,13 @@ public:
/// Are we running in either shutdown, or the polling thread.
bool isCorrectThread() const
{
if (std::this_thread::get_id() != _owner)
// 0 owner means detached and can be invoked by any thread.
if (_owner != std::thread::id(0) && std::this_thread::get_id() != _owner)
LOG_WRN("Incorrect thread affinity for " << _name << ". Expected: 0x" << std::hex <<
_owner << " (" << std::dec << Util::getThreadId() << ") but called from 0x" <<
std::hex << std::this_thread::get_id() << std::dec << ", stop: " << _stop);
return _stop || std::this_thread::get_id() == _owner;
return _stop || _owner == std::thread::id(0) || std::this_thread::get_id() == _owner;
}
/// Poll the sockets for available data to read or buffer to write.
@ -392,6 +394,7 @@ public:
{
LOG_DBG("Removing socket #" << _pollFds[i].fd << " (of " <<
_pollSockets.size() << ") from " << _name);
_pollSockets[i]->setThreadOwner(std::thread::id(0));
_pollSockets.erase(_pollSockets.begin() + i);
}
}