sfx2/source/control/itemdel.cxx |   47 ++++++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 13 deletions(-)

New commits:
commit 6a0d4247b73d16d7e70ab146aadfbed75721f8bd
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Jan 9 12:29:52 2024 +0100
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Jan 9 20:40:49 2024 +0100

    Revert "simplify SfxItemDisruptor_Impl, just use Application::PostUserEvent"
    
    This reverts commit 57145acf9ec47c23e307b7a5c0029d21d937cc35.
    
    According to 789a737ac92c4f2b0eb9820b99c43cc8253c8b29
    "Remove DeleteItemOnIdlex"
    
    There are some CrashReports in 7.6 which have
    DeleteItemOnIdle on the stack... DeleteItemOnIdle
    exists since 1st import, but was
    changed to AsyncEvent ca. 4 months ago (see
    57145acf9ec47c23e307b7a5c0029d21d937cc35), so that may
    have caused it.
    
    Reverting this patch in libreoffice-7-6 only to see if
    it fixes 
https://crashreport.libreoffice.org/stats/signature/static%20bool%20cppu::idefaultConstructElements(struct%20_sal_Sequence%20*%20*,%20struct%20_typelib_TypeDescriptionReference%20*,%20long,%20long,%20long)
    
    Change-Id: Ic6d1046e43295d719a928615a1be921ab5596326
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161823
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sfx2/source/control/itemdel.cxx b/sfx2/source/control/itemdel.cxx
index c96a9d0f4ba3..2b8e7db73fc6 100644
--- a/sfx2/source/control/itemdel.cxx
+++ b/sfx2/source/control/itemdel.cxx
@@ -22,35 +22,56 @@
 #include <itemdel.hxx>
 #include <svl/poolitem.hxx>
 #include <vcl/idle.hxx>
-#include <vcl/svapp.hxx>
 
 #include <tools/debug.hxx>
 
 class SfxItemDisruptor_Impl
 {
+    std::unique_ptr<SfxPoolItem> pItem;
+    Idle m_Idle;
+
+private:
+    DECL_LINK(Delete, Timer*, void);
+
 public:
-    static void DeleteItemOnIdle(std::unique_ptr<SfxPoolItem> pItem)
-    {
-        pItem->SetKind(SfxItemKind::DeleteOnIdle);
-        Application::PostUserEvent(LINK(nullptr, SfxItemDisruptor_Impl, 
Delete), pItem.release());
-        // coverity[leaked_storage] - pDisruptor takes care of its own 
destruction at idle time
-    }
-
-    DECL_STATIC_LINK(SfxItemDisruptor_Impl, Delete, void*, void);
+    explicit SfxItemDisruptor_Impl(std::unique_ptr<SfxPoolItem> 
pItemToDesrupt);
+    void LaunchDeleteOnIdle();
+    ~SfxItemDisruptor_Impl();
+    SfxItemDisruptor_Impl(const SfxItemDisruptor_Impl&) = delete;
+    SfxItemDisruptor_Impl& operator=(const SfxItemDisruptor_Impl&) = delete;
 };
 
-IMPL_STATIC_LINK(SfxItemDisruptor_Impl, Delete, void*, p, void)
+SfxItemDisruptor_Impl::SfxItemDisruptor_Impl(std::unique_ptr<SfxPoolItem> 
pItemToDisrupt)
+    : pItem(std::move(pItemToDisrupt))
+    , m_Idle("sfx::SfxItemDisruptor_Impl m_Idle")
+{
+    m_Idle.SetInvokeHandler(LINK(this, SfxItemDisruptor_Impl, Delete));
+    m_Idle.SetPriority(TaskPriority::DEFAULT_IDLE);
+
+    DBG_ASSERT(0 == pItem->GetRefCount(), "disrupting pooled item");
+    pItem->SetKind(SfxItemKind::DeleteOnIdle);
+}
+
+void SfxItemDisruptor_Impl::LaunchDeleteOnIdle() { m_Idle.Start(); }
+
+SfxItemDisruptor_Impl::~SfxItemDisruptor_Impl()
 {
-    SfxPoolItem* pItem = static_cast<SfxPoolItem*>(p);
+    m_Idle.Stop();
+
     // reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
     pItem->SetRefCount(0);
-    delete pItem;
+
+    pItem.reset();
 }
 
+IMPL_LINK_NOARG(SfxItemDisruptor_Impl, Delete, Timer*, void) { delete this; }
+
 void DeleteItemOnIdle(std::unique_ptr<SfxPoolItem> pItem)
 {
     DBG_ASSERT(0 == pItem->GetRefCount(), "deleting item in use");
-    SfxItemDisruptor_Impl::DeleteItemOnIdle(std::move(pItem));
+    SfxItemDisruptor_Impl* pDesruptor = new 
SfxItemDisruptor_Impl(std::move(pItem));
+    pDesruptor->LaunchDeleteOnIdle();
+    // coverity[leaked_storage] - pDesruptor takes care of its own destruction 
at idle time
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to