diff options
author | Tor Lillqvist <tml@collabora.com> | 2021-04-28 12:19:35 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2021-04-29 10:39:42 +0200 |
commit | e8c48afa77eb89ce34b03c559b279277384e28ae (patch) | |
tree | 2dbfe9fe199e9e53a522387a2fc33729a34e795b /include/comphelper | |
parent | Fix syntax error in generated JSON (diff) | |
download | core-e8c48afa77eb89ce34b03c559b279277384e28ae.tar.gz core-e8c48afa77eb89ce34b03c559b279277384e28ae.zip |
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/+/114800
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'include/comphelper')
-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 |