diff options
author | Tor Lillqvist <tml@collabora.com> | 2020-07-14 17:06:11 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2020-07-14 16:56:20 +0200 |
commit | 07bf5984305955725c1cfe0d5cada0b46d42dbc6 (patch) | |
tree | 68c6e395b4f05a2e4964b09c04e6def79c5dd9a3 /kit/Kit.cpp | |
parent | ef7e79a20b1ad487164eabe827092ed1da294690 (diff) |
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>
Diffstat (limited to 'kit/Kit.cpp')
-rw-r--r-- | kit/Kit.cpp | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/kit/Kit.cpp b/kit/Kit.cpp index f10493e50..284e552f3 100644 --- a/kit/Kit.cpp +++ b/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); } |