Use osl_atomic_increment/osl_atomic_decrement to change m_refCount

Change-Id: Ia24441d3671102fdeeb797547396c25ee2a6ffd3
Reviewed-on: https://gerrit.libreoffice.org/70382
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/UnoControls/source/controls/progressmonitor.cxx b/UnoControls/source/controls/progressmonitor.cxx
index 23451ac..2c728cb 100644
--- a/UnoControls/source/controls/progressmonitor.cxx
+++ b/UnoControls/source/controls/progressmonitor.cxx
@@ -48,7 +48,7 @@ ProgressMonitor::ProgressMonitor( const css::uno::Reference< XComponentContext >
{
    // It's not allowed to work with member in this method (refcounter !!!)
    // But with a HACK (++refcount) its "OK" :-(
    ++m_refCount;
    osl_atomic_increment(&m_refCount);

    // Create instances for fixedtext, button and progress ...

@@ -94,7 +94,7 @@ ProgressMonitor::ProgressMonitor( const css::uno::Reference< XComponentContext >
    m_xTopic_Bottom->setText ( PROGRESSMONITOR_DEFAULT_TOPIC );
    m_xText_Bottom->setText  ( PROGRESSMONITOR_DEFAULT_TEXT );

    --m_refCount;
    osl_atomic_decrement(&m_refCount);
}

ProgressMonitor::~ProgressMonitor()
diff --git a/UnoControls/source/controls/statusindicator.cxx b/UnoControls/source/controls/statusindicator.cxx
index c1c9d35..2b6a23b 100644
--- a/UnoControls/source/controls/statusindicator.cxx
+++ b/UnoControls/source/controls/statusindicator.cxx
@@ -42,7 +42,7 @@ StatusIndicator::StatusIndicator( const css::uno::Reference< XComponentContext >
{
    // It's not allowed to work with member in this method (refcounter !!!)
    // But with a HACK (++refcount) its "OK" :-(
    ++m_refCount;
    osl_atomic_increment(&m_refCount);

    // Create instances for fixedtext and progress ...
    m_xText.set( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY );
@@ -61,7 +61,7 @@ StatusIndicator::StatusIndicator( const css::uno::Reference< XComponentContext >
    // (progressbar take automatically its own defaults)
    m_xText->setText( "" );

    --m_refCount;
    osl_atomic_decrement(&m_refCount);
}

StatusIndicator::~StatusIndicator() {}
diff --git a/comphelper/source/container/enumhelper.cxx b/comphelper/source/container/enumhelper.cxx
index 41585ae..dc467bb 100644
--- a/comphelper/source/container/enumhelper.cxx
+++ b/comphelper/source/container/enumhelper.cxx
@@ -105,14 +105,14 @@ void OEnumerationByName::impl_startDisposeListening()
    if (m_bListening)
        return;

    ++m_refCount;
    osl_atomic_increment(&m_refCount);
    css::uno::Reference< css::lang::XComponent > xDisposable(m_xAccess, css::uno::UNO_QUERY);
    if (xDisposable.is())
    {
        xDisposable->addEventListener(this);
        m_bListening = true;
    }
    --m_refCount;
    osl_atomic_decrement(&m_refCount);
}


@@ -123,14 +123,14 @@ void OEnumerationByName::impl_stopDisposeListening()
    if (!m_bListening)
        return;

    ++m_refCount;
    osl_atomic_increment(&m_refCount);
    css::uno::Reference< css::lang::XComponent > xDisposable(m_xAccess, css::uno::UNO_QUERY);
    if (xDisposable.is())
    {
        xDisposable->removeEventListener(this);
        m_bListening = false;
    }
    --m_refCount;
    osl_atomic_decrement(&m_refCount);
}

OEnumerationByIndex::OEnumerationByIndex(const css::uno::Reference< css::container::XIndexAccess >& _rxAccess)
@@ -201,14 +201,14 @@ void OEnumerationByIndex::impl_startDisposeListening()
    if (m_bListening)
        return;

    ++m_refCount;
    osl_atomic_increment(&m_refCount);
    css::uno::Reference< css::lang::XComponent > xDisposable(m_xAccess, css::uno::UNO_QUERY);
    if (xDisposable.is())
    {
        xDisposable->addEventListener(this);
        m_bListening = true;
    }
    --m_refCount;
    osl_atomic_decrement(&m_refCount);
}


@@ -219,14 +219,14 @@ void OEnumerationByIndex::impl_stopDisposeListening()
    if (!m_bListening)
        return;

    ++m_refCount;
    osl_atomic_increment(&m_refCount);
    css::uno::Reference< css::lang::XComponent > xDisposable(m_xAccess, css::uno::UNO_QUERY);
    if (xDisposable.is())
    {
        xDisposable->removeEventListener(this);
        m_bListening = false;
    }
    --m_refCount;
    osl_atomic_decrement(&m_refCount);
}

OAnyEnumeration::OAnyEnumeration(const css::uno::Sequence< css::uno::Any >& lItems)
diff --git a/comphelper/source/misc/instancelocker.cxx b/comphelper/source/misc/instancelocker.cxx
index c995499..cf7a2cf 100644
--- a/comphelper/source/misc/instancelocker.cxx
+++ b/comphelper/source/misc/instancelocker.cxx
@@ -50,7 +50,7 @@ OInstanceLocker::~OInstanceLocker()
{
    if ( !m_bDisposed )
    {
        m_refCount++; // to call dispose
        osl_atomic_increment(&m_refCount); // to call dispose
        try {
            dispose();
        }
diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx
index 912cf3a..48da9ab 100644
--- a/embeddedobj/source/commonembedding/miscobj.cxx
+++ b/embeddedobj/source/commonembedding/miscobj.cxx
@@ -261,7 +261,7 @@ OCommonEmbeddedObject::~OCommonEmbeddedObject()
{
    if ( m_pInterfaceContainer || m_xDocHolder.is() )
    {
        m_refCount++;
        osl_atomic_increment(&m_refCount);
        try {
            lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );

diff --git a/embeddedobj/source/general/docholder.cxx b/embeddedobj/source/general/docholder.cxx
index 75f6128..997a610 100644
--- a/embeddedobj/source/general/docholder.cxx
+++ b/embeddedobj/source/general/docholder.cxx
@@ -173,7 +173,7 @@ DocumentHolder::DocumentHolder( const uno::Reference< uno::XComponentContext >& 
    m_aOutplaceFrameProps[1] <<= aArg;

    uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
    m_refCount++;
    osl_atomic_increment(&m_refCount);
    try
    {
        xDesktop->addTerminateListener( this );
@@ -181,7 +181,7 @@ DocumentHolder::DocumentHolder( const uno::Reference< uno::XComponentContext >& 
    catch ( const uno::Exception& )
    {
    }
    m_refCount--;
    osl_atomic_decrement(&m_refCount);

    aArg.Name = "ParentFrame";
    aArg.Value <<= xDesktop; //TODO/LATER: should use parent document frame
@@ -191,7 +191,7 @@ DocumentHolder::DocumentHolder( const uno::Reference< uno::XComponentContext >& 

DocumentHolder::~DocumentHolder()
{
    m_refCount++; // to allow deregistration as a listener
    osl_atomic_increment(&m_refCount); // to allow deregistration as a listener

    if( m_xFrame.is() )
        CloseFrame();
diff --git a/embeddedobj/source/msole/olemisc.cxx b/embeddedobj/source/msole/olemisc.cxx
index 3225b76..9a22ec9 100644
--- a/embeddedobj/source/msole/olemisc.cxx
+++ b/embeddedobj/source/msole/olemisc.cxx
@@ -142,7 +142,7 @@ OleEmbeddedObject::~OleEmbeddedObject()
    if ( m_pOleComponent || m_pInterfaceContainer || m_xObjectStream.is() )
    {
        // the component must be cleaned during closing
        m_refCount++; // to avoid crash
        osl_atomic_increment(&m_refCount); // to avoid crash
        try {
            Dispose();
        } catch( const uno::Exception& ) {}
diff --git a/package/source/xstor/ocompinstream.cxx b/package/source/xstor/ocompinstream.cxx
index af87464..98592e6 100644
--- a/package/source/xstor/ocompinstream.cxx
+++ b/package/source/xstor/ocompinstream.cxx
@@ -67,7 +67,7 @@ OInputCompStream::~OInputCompStream()

    if ( !m_bDisposed )
    {
        m_refCount++;
        osl_atomic_increment(&m_refCount);
        dispose();
    }
}
diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx
index 67f1520..ee06fc0 100644
--- a/package/source/xstor/owriteablestream.cxx
+++ b/package/source/xstor/owriteablestream.cxx
@@ -1668,7 +1668,7 @@ OWriteStream::~OWriteStream()
    ::osl::MutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
    if ( m_pImpl )
    {
        m_refCount++;
        osl_atomic_increment(&m_refCount);
        try {
            dispose();
        }
diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx
index 20dff27..fe12788 100644
--- a/package/source/xstor/xstorage.cxx
+++ b/package/source/xstor/xstorage.cxx
@@ -1793,7 +1793,7 @@ OStorage::~OStorage()
    ::osl::MutexGuard aGuard( m_pData->m_xSharedMutex->GetMutex() );
    if ( m_pImpl )
    {
        m_refCount++; // to call dispose
        osl_atomic_increment(&m_refCount); // to call dispose
        try {
            dispose();
        }
diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx
index d6cd528..0125283 100644
--- a/package/source/zippackage/zipfileaccess.cxx
+++ b/package/source/zippackage/zipfileaccess.cxx
@@ -61,7 +61,8 @@ OZipFileAccess::~OZipFileAccess()
    if ( !m_bDisposed )
    {
        try {
            m_refCount++; // dispose will use refcounting so the further destruction must be avoided
             // dispose will use refcounting so the further destruction must be avoided
            osl_atomic_increment(&m_refCount);
            dispose();
        } catch( uno::Exception& )
        {}
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index c87a185..e1c0eb5 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -1409,12 +1409,12 @@ ScCellRangesBase::ScCellRangesBase(ScDocShell* pDocSh, const ScRange& rR) :
{
    // this is a hack to get m_wThis initialized; ideally there would be
    // factory functions doing this but there are so many subclasses of this...
    ++m_refCount;
    osl_atomic_increment(&m_refCount);
    {
        m_wThis = uno::Reference<uno::XInterface>(
                    static_cast<cppu::OWeakObject*>(this));
    }
    --m_refCount;
    osl_atomic_decrement(&m_refCount);

    ScRange aCellRange(rR);
    aCellRange.PutInOrder();
@@ -1441,12 +1441,12 @@ ScCellRangesBase::ScCellRangesBase(ScDocShell* pDocSh, const ScRangeList& rR) :
{
    // this is a hack to get m_wThis initialized; ideally there would be
    // factory functions doing this but there are so many subclasses of this...
    ++m_refCount;
    osl_atomic_increment(&m_refCount);
    {
        m_wThis = uno::Reference<uno::XInterface>(
                    static_cast<cppu::OWeakObject*>(this));
    }
    --m_refCount;
    osl_atomic_decrement(&m_refCount);

    if (pDocShell)  // Null if created with createInstance
    {
diff --git a/sfx2/source/notify/globalevents.cxx b/sfx2/source/notify/globalevents.cxx
index 6dd0340..cf15a8b 100644
--- a/sfx2/source/notify/globalevents.cxx
+++ b/sfx2/source/notify/globalevents.cxx
@@ -143,10 +143,10 @@ SfxGlobalEvents_Impl::SfxGlobalEvents_Impl( const uno::Reference < uno::XCompone
    , m_aLegacyListeners      (m_aLock)
    , m_aDocumentListeners    (m_aLock)
{
    m_refCount++;
    osl_atomic_increment(&m_refCount);
    SfxApplication::GetOrCreate();
    m_xEvents = new GlobalEventConfig();
    m_refCount--;
    osl_atomic_decrement(&m_refCount);
}

uno::Reference< container::XNameReplace > SAL_CALL SfxGlobalEvents_Impl::getEvents()
diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx
index 3541192..8647dd7 100644
--- a/sfx2/source/view/sfxbasecontroller.cxx
+++ b/sfx2/source/view/sfxbasecontroller.cxx
@@ -181,12 +181,12 @@ public:
                                , pWorkWindow( pWork )
                                , _nStartTime(0)
                            {
                                ++m_refCount;
                                osl_atomic_increment(&m_refCount);
                                Reference< lang::XComponent > xComponent(
                                    static_cast< ::cppu::OWeakObject* >(pController), uno::UNO_QUERY );
                                if (xComponent.is())
                                    xComponent->addEventListener(this);
                                --m_refCount;
                                osl_atomic_decrement(&m_refCount);
                            }

    virtual void SAL_CALL   start(const OUString& aText, sal_Int32 nRange) override;
diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx b/sot/source/unoolestorage/xolesimplestorage.cxx
index 1de1f56..926b32e 100644
--- a/sot/source/unoolestorage/xolesimplestorage.cxx
+++ b/sot/source/unoolestorage/xolesimplestorage.cxx
@@ -140,7 +140,7 @@ OLESimpleStorage::OLESimpleStorage(
OLESimpleStorage::~OLESimpleStorage()
{
    try {
        m_refCount++;
        osl_atomic_increment(&m_refCount);
        dispose();
    } catch( uno::Exception& )
    {}
diff --git a/svl/source/fsstor/fsstorage.cxx b/svl/source/fsstor/fsstorage.cxx
index c1727b9..54b09af 100644
--- a/svl/source/fsstor/fsstorage.cxx
+++ b/svl/source/fsstor/fsstorage.cxx
@@ -102,7 +102,7 @@ FSStorage::FSStorage( const ::ucbhelper::Content& aContent,
FSStorage::~FSStorage()
{
    ::osl::MutexGuard aGuard( m_aMutex );
    m_refCount++; // to call dispose
    osl_atomic_increment(&m_refCount); // to call dispose
    try {
        dispose();
    }
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index d8be8a2..0c40601 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -904,10 +904,10 @@ SwXShape::SwXShape(uno::Reference<uno::XInterface> & xShape,
        }
    }
    xShape = nullptr;
    m_refCount++;
    osl_atomic_increment(&m_refCount);
    if( xShapeAgg.is() )
        xShapeAgg->setDelegator( static_cast<cppu::OWeakObject*>(this) );
    m_refCount--;
    osl_atomic_decrement(&m_refCount);

    uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShapeAgg, uno::UNO_QUERY);
    SvxShape* pShape = nullptr;
diff --git a/sw/source/uibase/dbui/dbtree.cxx b/sw/source/uibase/dbui/dbtree.cxx
index a0fb9e0..f5d6c5c 100644
--- a/sw/source/uibase/dbui/dbtree.cxx
+++ b/sw/source/uibase/dbui/dbtree.cxx
@@ -83,13 +83,13 @@ SwDBTreeList_Impl::~SwDBTreeList_Impl()
{
    if(m_xDatabaseContext.is())
    {
        m_refCount++;
        osl_atomic_increment(&m_refCount);
        //block necessary due to solaris' compiler behaviour to
        //remove temporaries at the block's end
        {
            m_xDatabaseContext->removeContainerListener( this );
        }
        m_refCount--;
        osl_atomic_decrement(&m_refCount);
    }
}

diff --git a/sw/source/uibase/uiview/uivwimp.cxx b/sw/source/uibase/uiview/uivwimp.cxx
index 6c81a70..f2d9fdc 100644
--- a/sw/source/uibase/uiview/uivwimp.cxx
+++ b/sw/source/uibase/uiview/uivwimp.cxx
@@ -224,7 +224,7 @@ void SwView_Impl::Invalidate()
void SwView_Impl::AddTransferable(SwTransferable& rTransferable)
{
    //prevent removing of the non-referenced SwTransferable
    rTransferable.m_refCount++;
    osl_atomic_increment(&rTransferable.m_refCount);
    {
        // Remove previously added, but no longer existing weak references.
        mxTransferables.erase(std::remove_if(mxTransferables.begin(), mxTransferables.end(),
@@ -235,7 +235,7 @@ void SwView_Impl::AddTransferable(SwTransferable& rTransferable)

        mxTransferables.emplace_back(uno::Reference<lang::XUnoTunnel>(&rTransferable));
    }
    rTransferable.m_refCount--;
    osl_atomic_decrement(&rTransferable.m_refCount);
}

void SwView_Impl::StartDocumentInserter(
diff --git a/sw/source/uibase/uno/unodispatch.cxx b/sw/source/uibase/uno/unodispatch.cxx
index 9facfa8..c97431b 100644
--- a/sw/source/uibase/uno/unodispatch.cxx
+++ b/sw/source/uibase/uno/unodispatch.cxx
@@ -46,14 +46,14 @@ SwXDispatchProviderInterceptor::SwXDispatchProviderInterceptor(SwView& rVw) :
    m_xIntercepted.set(xUnoFrame, uno::UNO_QUERY);
    if(m_xIntercepted.is())
    {
        m_refCount++;
        osl_atomic_increment(&m_refCount);
        m_xIntercepted->registerDispatchProviderInterceptor(static_cast<frame::XDispatchProviderInterceptor*>(this));
        // this should make us the top-level dispatch-provider for the component, via a call to our
        // setDispatchProvider we should have got an fallback for requests we (i.e. our master) cannot fulfill
        uno::Reference< lang::XComponent> xInterceptedComponent(m_xIntercepted, uno::UNO_QUERY);
        if (xInterceptedComponent.is())
            xInterceptedComponent->addEventListener(static_cast<lang::XEventListener*>(this));
        m_refCount--;
        osl_atomic_decrement(&m_refCount);
    }
}

diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx
index dd4b8c1..2be2195 100644
--- a/sw/source/uibase/uno/unotxvw.cxx
+++ b/sw/source/uibase/uno/unotxvw.cxx
@@ -120,7 +120,7 @@ void SwXTextView::Invalidate()
        mxTextViewCursor.clear();
    }

    m_refCount++; //prevent second d'tor call
    osl_atomic_increment(&m_refCount); //prevent second d'tor call

    {
        uno::Reference<uno::XInterface> const xInt(static_cast<
@@ -129,7 +129,7 @@ void SwXTextView::Invalidate()
        m_SelChangedListeners.disposeAndClear(aEvent);
    }

    m_refCount--;
    osl_atomic_decrement(&m_refCount);
    m_pView = nullptr;
}