wsd: remove sockets when stopping poll thread
And assume correct thread if poll thread is not running (i.e. no race). Change-Id: I17958e682aba434ebb47fe0de199b9f530b54dee Reviewed-on: https://gerrit.libreoffice.org/36183 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
parent
01519eff70
commit
4a7a0fb477
2 changed files with 20 additions and 1 deletions
|
@ -264,7 +264,23 @@ public:
|
|||
/// Stop the polling thread.
|
||||
void stop()
|
||||
{
|
||||
LOG_DBG("Stopping " << _name << " and removing all sockets.");
|
||||
_stop = true;
|
||||
|
||||
assert(socket);
|
||||
assertCorrectThread();
|
||||
|
||||
while (!_pollSockets.empty())
|
||||
{
|
||||
const std::shared_ptr<Socket>& socket = _pollSockets.back();
|
||||
|
||||
LOG_DBG("Removing socket #" << socket->getFD() << " from " << _name);
|
||||
socket->assertCorrectThread();
|
||||
socket->setThreadOwner(std::thread::id(0));
|
||||
|
||||
_pollSockets.pop_back();
|
||||
}
|
||||
|
||||
wakeup();
|
||||
}
|
||||
|
||||
|
@ -293,7 +309,7 @@ public:
|
|||
void assertCorrectThread() const
|
||||
{
|
||||
// 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);
|
||||
const bool sameThread = (!isAlive() || _owner == std::thread::id(0) || std::this_thread::get_id() == _owner);
|
||||
if (!sameThread)
|
||||
LOG_ERR("Incorrect thread affinity for " << _name << ". Expected: 0x" << std::hex <<
|
||||
_owner << " (" << std::dec << Util::getThreadId() << ") but called from 0x" <<
|
||||
|
|
|
@ -264,6 +264,9 @@ void DocumentBroker::pollThread()
|
|||
_poll->poll(std::min(flushTimeoutMs - elapsedMs, POLL_TIMEOUT_MS / 5));
|
||||
}
|
||||
|
||||
// Stop to mark it done and cleanup.
|
||||
_poll->stop();
|
||||
|
||||
// Async cleanup.
|
||||
LOOLWSD::doHousekeeping();
|
||||
|
||||
|
|
Loading…
Reference in a new issue