Make objects and threads go away more reliably in the iOS app
We probably used to have circular references that made KitSocketPoll and KitWebSocketHandler objects hang around forever, or something. (Not a problem in web-based Online where kit processes have a restricted lifetime.) Change-Id: Ia6eebc51f4a4a8fb4f69a2c83a0131de921ea1d6 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98744 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tor Lillqvist <tml@collabora.com>
This commit is contained in:
parent
ef7e79a20b
commit
07bf598430
2 changed files with 22 additions and 28 deletions
49
kit/Kit.cpp
49
kit/Kit.cpp
|
@ -1623,19 +1623,7 @@ class KitSocketPoll final : public SocketPoll
|
|||
public:
|
||||
~KitSocketPoll()
|
||||
{
|
||||
#ifdef IOS
|
||||
std::unique_lock<std::mutex> lock(KSPollsMutex);
|
||||
std::shared_ptr<KitSocketPoll> p;
|
||||
auto i = KSPolls.begin();
|
||||
for (; i != KSPolls.end(); ++i)
|
||||
{
|
||||
p = i->lock();
|
||||
if (p && p.get() == this)
|
||||
break;
|
||||
}
|
||||
assert(i != KSPolls.end());
|
||||
KSPolls.erase(i);
|
||||
#endif
|
||||
// Just to make it easier to set a breakpoint
|
||||
}
|
||||
|
||||
static std::shared_ptr<KitSocketPoll> create()
|
||||
|
@ -1645,7 +1633,6 @@ public:
|
|||
#ifdef IOS
|
||||
std::unique_lock<std::mutex> lock(KSPollsMutex);
|
||||
KSPolls.push_back(result);
|
||||
// KSPollsCV.notify_one();
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
@ -1762,6 +1749,11 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
~KitWebSocketHandler()
|
||||
{
|
||||
// Just to make it easier to set a breakpoint
|
||||
}
|
||||
|
||||
protected:
|
||||
void handleMessage(const std::vector<char>& data) override
|
||||
{
|
||||
|
@ -1881,10 +1873,13 @@ protected:
|
|||
SigUtil::setTerminationFlag();
|
||||
#endif
|
||||
#ifdef IOS
|
||||
std::unique_lock<std::mutex> lock(_ksPoll->terminationMutex);
|
||||
_ksPoll->terminationFlag = true;
|
||||
_ksPoll->terminationCV.notify_all();
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_ksPoll->terminationMutex);
|
||||
_ksPoll->terminationFlag = true;
|
||||
_ksPoll->terminationCV.notify_all();
|
||||
}
|
||||
#endif
|
||||
_ksPoll.reset();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1903,22 +1898,20 @@ int pollCallback(void* pData, int timeoutUs)
|
|||
return reinterpret_cast<KitSocketPoll*>(pData)->kitPoll(timeoutUs);
|
||||
#else
|
||||
std::unique_lock<std::mutex> lock(KitSocketPoll::KSPollsMutex);
|
||||
if (KitSocketPoll::KSPolls.size() == 0)
|
||||
std::vector<std::shared_ptr<KitSocketPoll>> v;
|
||||
for (const auto &i : KitSocketPoll::KSPolls)
|
||||
{
|
||||
auto p = i.lock();
|
||||
if (p)
|
||||
v.push_back(p);
|
||||
}
|
||||
lock.unlock();
|
||||
if (v.size() == 0)
|
||||
{
|
||||
// KitSocketPoll::KSPollsCV.wait(lock);
|
||||
lock.unlock();
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(timeoutUs));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::shared_ptr<KitSocketPoll>> v;
|
||||
for (const auto &i : KitSocketPoll::KSPolls)
|
||||
{
|
||||
auto p = i.lock();
|
||||
if (p)
|
||||
v.push_back(p);
|
||||
}
|
||||
lock.unlock();
|
||||
for (const auto &p : v)
|
||||
p->kitPoll(timeoutUs);
|
||||
}
|
||||
|
|
|
@ -799,6 +799,7 @@ public:
|
|||
{
|
||||
assertCorrectThread();
|
||||
_socketHandler->onDisconnect();
|
||||
_socketHandler.reset();
|
||||
}
|
||||
|
||||
if (!_shutdownSignalled)
|
||||
|
|
Loading…
Reference in a new issue