diff options
author | Tor Lillqvist <tml@collabora.com> | 2021-04-28 12:19:35 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2021-04-29 15:34:20 +0200 |
commit | 347ef2de1be9fe4c34545c205826817f79342a5a (patch) | |
tree | 3c2661f7e767f6692ecc15f4858531d69921a46e /include | |
parent | 414b40408acf7688d9ce9f9ee8c5ab4b2226a2ae (diff) |
Add AsyncEvent::finish() to end a nested AsyncEvent before its parent ends
Add unit testing of that, too.
Change-Id: Iae5fb6da0b7fcabe8f555d800f065b6f5b4b9982
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114786
Tested-by: Tor Lillqvist <tml@collabora.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/comphelper/traceevent.hxx | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/include/comphelper/traceevent.hxx b/include/comphelper/traceevent.hxx index 33eaf04c7047..eed67c0c6f9b 100644 --- a/include/comphelper/traceevent.hxx +++ b/include/comphelper/traceevent.hxx @@ -14,6 +14,7 @@ #include <atomic> #include <memory> +#include <set> #include <vector> #include <osl/process.h> @@ -81,7 +82,8 @@ class COMPHELPER_DLLPUBLIC AsyncEvent : public NamedEvent, static int s_nIdCounter; int m_nId; int m_nPid; - std::vector<std::shared_ptr<AsyncEvent>> m_aChildren; + std::set<std::shared_ptr<AsyncEvent>> m_aChildren; + std::weak_ptr<AsyncEvent> m_pParent; bool m_bBeginRecorded; AsyncEvent(const char* sName, int nId) @@ -159,11 +161,23 @@ public: if (s_bRecording && pParent->m_bBeginRecorded) { pResult.reset(new AsyncEvent(sName, pParent->m_nId)); - pParent->m_aChildren.push_back(pResult); + pParent->m_aChildren.insert(pResult); + pResult->m_pParent = pParent; } return pResult; } + + void finish() + { + // This makes sense to call only for a nested AsyncEvent. To finish up a non-nested AsyncEvent you + // just need to release your sole owning pointer to it. + auto pParent = m_pParent.lock(); + if (!pParent) + return; + pParent->m_aChildren.erase(shared_from_this()); + m_aChildren.clear(); + } }; } // namespace comphelper |