summaryrefslogtreecommitdiff
path: root/include/comphelper
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2021-04-28 12:19:35 +0300
committerTor Lillqvist <tml@collabora.com>2021-04-29 08:46:02 +0200
commit2cc42f656b24b6e506fecb61f0fc58f5f8a98e6a (patch)
treea209196e3e72dda0e3669a30e4d5ac2fae852909 /include/comphelper
parent0e383fa31da530161263ef02f4e7c464f4d7b53e (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/+/114771 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'include/comphelper')
-rw-r--r--include/comphelper/traceevent.hxx18
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