include/vcl/settings.hxx    |   47 +++++------
 vcl/source/app/settings.cxx |  178 ++++++++------------------------------------
 2 files changed, 55 insertions(+), 170 deletions(-)

New commits:
commit a9cfb745c5ade8b05b97a33c4cb5cc66941b803d
Author: Tobias Lippert <d...@fastmail.fm>
Date:   Sat Jan 11 21:03:11 2014 +0100

    Replace handwritten reference counting with shared_ptr
    
    This will help to avoid race conditions because the shared pointers
    are thread safe and use atomic increments.
    
    Conflicts:
        include/vcl/settings.hxx
        vcl/source/app/settings.cxx
    
    Change-Id: Ie3d27d6412167855a0cea1442676b81b733c15e8

diff --git a/include/vcl/settings.hxx b/include/vcl/settings.hxx
index 0173b31..828c7a1 100644
--- a/include/vcl/settings.hxx
+++ b/include/vcl/settings.hxx
@@ -30,6 +30,8 @@
 #include <i18nlangtag/languagetag.hxx>
 #include <unotools/syslocale.hxx>
 
+#include <boost/shared_ptr.hpp>
+
 class CollatorWrapper;
 class LocaleDataWrapper;
 
@@ -44,12 +46,11 @@ namespace vcl {
 class ImplMouseData
 {
     friend class MouseSettings;
-
+public:
                                     ImplMouseData();
                                     ImplMouseData( const ImplMouseData& rData 
);
 
 private:
-    sal_uLong                           mnRefCount;
     sal_uLong                           mnOptions;
     sal_uLong                           mnDoubleClkTime;
     long                            mnDoubleClkWidth;
@@ -97,7 +98,7 @@ class VCL_DLLPUBLIC MouseSettings
     void                            CopyData();
 
 private:
-    ImplMouseData*                  mpData;
+    boost::shared_ptr<ImplMouseData>                  mpData;
 
 public:
                                     MouseSettings();
@@ -241,13 +242,12 @@ class ImplStyleData
 {
     friend class StyleSettings;
 
+public:
                                     ImplStyleData();
                                     ImplStyleData( const ImplStyleData& rData 
);
-    void                            SetStandardStyles();
 
 private:
-    sal_uLong                           mnRefCount;
-
+    void                            SetStandardStyles();
     Color                           maActiveBorderColor;
     Color                           maActiveColor;
     Color                           maActiveColor2;
@@ -434,7 +434,7 @@ class VCL_DLLPUBLIC StyleSettings
     void                            CopyData();
 
 private:
-    ImplStyleData*                  mpData;
+    boost::shared_ptr<ImplStyleData>                  mpData;
 
 public:
                                     StyleSettings();
@@ -833,8 +833,8 @@ public:
 
     void                            SetOptions( sal_uLong nOptions )
                                         { CopyData(); mpData->mnOptions = 
nOptions; }
-    sal_uLong                           GetOptions() const
-                                        { return mpData->mnOptions; }
+    sal_uLong                           GetOptions() const;
+
     void                            SetAutoMnemonic( bool bAutoMnemonic )
                                         { CopyData(); mpData->mnAutoMnemonic = 
(sal_uInt16)bAutoMnemonic; }
     bool                            GetAutoMnemonic() const
@@ -958,15 +958,15 @@ protected:
 class ImplMiscData
 {
     friend class MiscSettings;
+public:
 
                                     ImplMiscData();
                                     ImplMiscData( const ImplMiscData& rData );
 
 private:
-    sal_uLong                           mnRefCount;
-    AutoState                          mnEnableATT;
+    AutoState                       mnEnableATT;
     bool                            mbEnableLocalizedDecimalSep;
-    AutoState                          mnDisablePrinting;
+    AutoState                       mnDisablePrinting;
 };
 
 // ----------------
@@ -978,7 +978,7 @@ class VCL_DLLPUBLIC MiscSettings
     void                            CopyData();
 
 private:
-    ImplMiscData*                   mpData;
+    boost::shared_ptr<ImplMiscData>                   mpData;
 
 public:
                                     MiscSettings();
@@ -1006,12 +1006,11 @@ public:
 class ImplHelpData
 {
     friend class HelpSettings;
-
+public:
                                     ImplHelpData();
                                     ImplHelpData( const ImplHelpData& rData );
 
 private:
-    sal_uLong                           mnRefCount;
     sal_uLong                           mnOptions;
     sal_uLong                           mnTipDelay;
     sal_uLong                           mnTipTimeout;
@@ -1027,7 +1026,7 @@ class VCL_DLLPUBLIC HelpSettings
     void                            CopyData();
 
 private:
-    ImplHelpData*                   mpData;
+    boost::shared_ptr<ImplHelpData>                   mpData;
 
 public:
                                     HelpSettings();
@@ -1063,14 +1062,13 @@ public:
 // -----------------------
 class ImplAllSettingsData
 {
-    friend class    AllSettings;
-
-                    ImplAllSettingsData();
-                    ImplAllSettingsData( const ImplAllSettingsData& rData );
-                    ~ImplAllSettingsData();
+public:
+    ImplAllSettingsData();
+    ImplAllSettingsData( const ImplAllSettingsData& rData );
+    ~ImplAllSettingsData();
 
+    friend class    AllSettings;
 private:
-    sal_uLong                               mnRefCount;
     MouseSettings                           maMouseSettings;
     StyleSettings                           maStyleSettings;
     MiscSettings                            maMiscSettings;
@@ -1111,7 +1109,7 @@ class VCL_DLLPUBLIC AllSettings
     void                                    CopyData();
 
 private:
-    ImplAllSettingsData*                    mpData;
+    boost::shared_ptr<ImplAllSettingsData>                    mpData;
 
 public:
                                             AllSettings();
@@ -1125,8 +1123,7 @@ public:
 
     void                                    SetStyleSettings( const 
StyleSettings& rSet )
                                                 { CopyData(); 
mpData->maStyleSettings = rSet; }
-    const StyleSettings&                    GetStyleSettings() const
-                                                { return 
mpData->maStyleSettings; }
+    const StyleSettings&                    GetStyleSettings() const;
 
     void                                    SetMiscSettings( const 
MiscSettings& rSet )
                                                 { CopyData(); 
mpData->maMiscSettings = rSet; }
diff --git a/vcl/source/app/settings.cxx b/vcl/source/app/settings.cxx
index a5b7dd9..9714747 100644
--- a/vcl/source/app/settings.cxx
+++ b/vcl/source/app/settings.cxx
@@ -48,6 +48,9 @@ using namespace ::com::sun::star;
 
 #include "svdata.hxx"
 #include "impimagetree.hxx"
+
+#include <boost/make_shared.hpp>
+
 // =======================================================================
 
 
@@ -55,7 +58,6 @@ using namespace ::com::sun::star;
 
 ImplMouseData::ImplMouseData()
 {
-    mnRefCount                  = 1;
     mnOptions                   = 0;
     mnDoubleClkTime             = 500;
     mnDoubleClkWidth            = 2;
@@ -83,7 +85,6 @@ ImplMouseData::ImplMouseData()
 
 ImplMouseData::ImplMouseData( const ImplMouseData& rData )
 {
-    mnRefCount                  = 1;
     mnOptions                   = rData.mnOptions;
     mnDoubleClkTime             = rData.mnDoubleClkTime;
     mnDoubleClkWidth            = rData.mnDoubleClkWidth;
@@ -110,49 +111,28 @@ ImplMouseData::ImplMouseData( const ImplMouseData& rData )
 // -----------------------------------------------------------------------
 
 MouseSettings::MouseSettings()
+: mpData(boost::make_shared<ImplMouseData>())
 {
-    mpData = new ImplMouseData();
 }
 
 // -----------------------------------------------------------------------
 
 MouseSettings::MouseSettings( const MouseSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "MouseSettings: RefCount 
overflow" );
-
-    // copy shared instance data and increment reference counter
     mpData = rSet.mpData;
-    mpData->mnRefCount++;
 }
 
 // -----------------------------------------------------------------------
 
 MouseSettings::~MouseSettings()
 {
-    // delete data if last reference
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
 }
 
 // -----------------------------------------------------------------------
 
 const MouseSettings& MouseSettings::operator =( const MouseSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "MouseSettings: RefCount 
overflow" );
-
-    // increment reference counter first, to be able to assign oneself
-    rSet.mpData->mnRefCount++;
-
-    // delete data if last reference
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
-
     mpData = rSet.mpData;
-
     return *this;
 }
 
@@ -160,11 +140,9 @@ const MouseSettings& MouseSettings::operator =( const 
MouseSettings& rSet )
 
 void MouseSettings::CopyData()
 {
-    // copy if another references exist
-    if ( mpData->mnRefCount != 1 )
-    {
-        mpData->mnRefCount--;
-        mpData = new ImplMouseData( *mpData );
+    // copy if other references exist
+    if ( ! mpData.unique() ) {
+        mpData = boost::make_shared<ImplMouseData>(*mpData);
     }
 }
 
@@ -208,7 +186,6 @@ ImplStyleData::ImplStyleData() :
     maPersonaHeaderBitmap(),
     maPersonaFooterBitmap()
 {
-    mnRefCount                  = 1;
     mnScrollBarSize             = 16;
     mnMinThumbSize              = 16;
     mnSplitSize                 = 3;
@@ -318,7 +295,6 @@ ImplStyleData::ImplStyleData( const ImplStyleData& rData ) :
     maPersonaHeaderBitmap( rData.maPersonaHeaderBitmap ),
     maPersonaFooterBitmap( rData.maPersonaFooterBitmap )
 {
-    mnRefCount                  = 1;
     mnBorderSize                = rData.mnBorderSize;
     mnTitleHeight               = rData.mnTitleHeight;
     mnFloatTitleHeight          = rData.mnFloatTitleHeight;
@@ -463,30 +439,21 @@ void ImplStyleData::SetStandardStyles()
 // -----------------------------------------------------------------------
 
 StyleSettings::StyleSettings()
+: mpData(boost::make_shared<ImplStyleData>())
 {
-    mpData = new ImplStyleData();
 }
 
 // -----------------------------------------------------------------------
 
 StyleSettings::StyleSettings( const StyleSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "StyleSettings: RefCount 
overflow" );
-
-    // copy shared instance data and increment reference counter
     mpData = rSet.mpData;
-    mpData->mnRefCount++;
 }
 
 // -----------------------------------------------------------------------
 
 StyleSettings::~StyleSettings()
 {
-    // if last reference then delete data
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
 }
 
 const Size& StyleSettings::GetListBoxPreviewDefaultPixelSize() const
@@ -853,19 +820,7 @@ Color StyleSettings::GetSeparatorColor() const
 
 const StyleSettings& StyleSettings::operator =( const StyleSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "StyleSettings: RefCount 
overflow" );
-
-    // increase reference counter first, to be able to assign oneself
-    rSet.mpData->mnRefCount++;
-
-    // if last reference then delete data
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
-
     mpData = rSet.mpData;
-
     return *this;
 }
 
@@ -874,10 +829,8 @@ const StyleSettings& StyleSettings::operator =( const 
StyleSettings& rSet )
 void StyleSettings::CopyData()
 {
     // copy if other references exist
-    if ( mpData->mnRefCount != 1 )
-    {
-        mpData->mnRefCount--;
-        mpData = new ImplStyleData( *mpData );
+    if ( ! mpData.unique() ) {
+        mpData = boost::make_shared<ImplStyleData>(*mpData);
     }
 }
 
@@ -1002,7 +955,6 @@ bool StyleSettings::operator ==( const StyleSettings& rSet 
) const
 
 ImplMiscData::ImplMiscData()
 {
-    mnRefCount                  = 1;
     mnEnableATT                 = AUTO_STATE_AUTO;
     mnDisablePrinting           = AUTO_STATE_AUTO;
     static const char* pEnv = getenv("SAL_DECIMALSEP_ENABLED" ); // set 
default without UI
@@ -1013,7 +965,6 @@ ImplMiscData::ImplMiscData()
 
 ImplMiscData::ImplMiscData( const ImplMiscData& rData )
 {
-    mnRefCount                  = 1;
     mnEnableATT                 = rData.mnEnableATT;
     mnDisablePrinting           = rData.mnDisablePrinting;
     mbEnableLocalizedDecimalSep = rData.mbEnableLocalizedDecimalSep;
@@ -1022,49 +973,28 @@ ImplMiscData::ImplMiscData( const ImplMiscData& rData )
 // -----------------------------------------------------------------------
 
 MiscSettings::MiscSettings()
+: mpData(boost::make_shared<ImplMiscData>())
 {
-    mpData = new ImplMiscData();
 }
 
 // -----------------------------------------------------------------------
 
 MiscSettings::MiscSettings( const MiscSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "MiscSettings: RefCount 
overflow" );
-
-    // copy shared instance data and increment reference counter
     mpData = rSet.mpData;
-    mpData->mnRefCount++;
 }
 
 // -----------------------------------------------------------------------
 
 MiscSettings::~MiscSettings()
 {
-    // if last reference then delete data
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
 }
 
 // -----------------------------------------------------------------------
 
 const MiscSettings& MiscSettings::operator =( const MiscSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "MiscSettings: RefCount 
overflow" );
-
-    //  increase reference counter first, to be able to assign oneself
-    rSet.mpData->mnRefCount++;
-
-    // if last reference then delete data
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
-
     mpData = rSet.mpData;
-
     return *this;
 }
 
@@ -1073,10 +1003,8 @@ const MiscSettings& MiscSettings::operator =( const 
MiscSettings& rSet )
 void MiscSettings::CopyData()
 {
     // copy if other references exist
-    if ( mpData->mnRefCount != 1 )
-    {
-        mpData->mnRefCount--;
-        mpData = new ImplMiscData( *mpData );
+    if ( ! mpData.unique() ) {
+        mpData = boost::make_shared<ImplMiscData>(*mpData);
     }
 }
 
@@ -1251,7 +1179,6 @@ bool MiscSettings::GetEnableLocalizedDecimalSep() const
 
 ImplHelpData::ImplHelpData()
 {
-    mnRefCount                  = 1;
     mnOptions                   = 0;
     mnTipDelay                  = 500;
     mnTipTimeout                = 3000;
@@ -1262,7 +1189,6 @@ ImplHelpData::ImplHelpData()
 
 ImplHelpData::ImplHelpData( const ImplHelpData& rData )
 {
-    mnRefCount                  = 1;
     mnOptions                   = rData.mnOptions;
     mnTipDelay                  = rData.mnTipDelay;
     mnTipTimeout                = rData.mnTipTimeout;
@@ -1272,49 +1198,28 @@ ImplHelpData::ImplHelpData( const ImplHelpData& rData )
 // -----------------------------------------------------------------------
 
 HelpSettings::HelpSettings()
+: mpData(boost::make_shared<ImplHelpData>())
 {
-    mpData = new ImplHelpData();
 }
 
 // -----------------------------------------------------------------------
 
 HelpSettings::HelpSettings( const HelpSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "HelpSettings: RefCount 
overflow" );
-
-    // copy shared instance data and increment reference counter
     mpData = rSet.mpData;
-    mpData->mnRefCount++;
 }
 
 // -----------------------------------------------------------------------
 
 HelpSettings::~HelpSettings()
 {
-    // if last reference then delete data
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
 }
 
 // -----------------------------------------------------------------------
 
 const HelpSettings& HelpSettings::operator =( const HelpSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "HelpSettings: RefCount 
overflow" );
-
-    // increase reference counter first, to be able to assign oneself
-    rSet.mpData->mnRefCount++;
-
-    // delete data if last reference
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
-
     mpData = rSet.mpData;
-
     return *this;
 }
 
@@ -1322,11 +1227,9 @@ const HelpSettings& HelpSettings::operator =( const 
HelpSettings& rSet )
 
 void HelpSettings::CopyData()
 {
-    // copy of other references exist
-    if ( mpData->mnRefCount != 1 )
-    {
-        mpData->mnRefCount--;
-        mpData = new ImplHelpData( *mpData );
+    // copy if other references exist
+    if ( ! mpData.unique() ) {
+        mpData = boost::make_shared<ImplHelpData>(*mpData);
     }
 }
 
@@ -1353,7 +1256,6 @@ ImplAllSettingsData::ImplAllSettingsData()
         maLocale( LANGUAGE_SYSTEM ),
         maUILocale( LANGUAGE_SYSTEM )
 {
-    mnRefCount                  = 1;
     mnSystemUpdate              = SETTINGS_ALLSETTINGS;
     mnWindowUpdate              = SETTINGS_ALLSETTINGS;
     mpLocaleDataWrapper         = NULL;
@@ -1373,7 +1275,6 @@ ImplAllSettingsData::ImplAllSettingsData( const 
ImplAllSettingsData& rData ) :
     maLocale( rData.maLocale ),
     maUILocale( rData.maUILocale )
 {
-    mnRefCount                  = 1;
     mnSystemUpdate              = rData.mnSystemUpdate;
     mnWindowUpdate              = rData.mnWindowUpdate;
     // Pointer couldn't shared and objects haven't a copy ctor
@@ -1400,51 +1301,28 @@ ImplAllSettingsData::~ImplAllSettingsData()
 // -----------------------------------------------------------------------
 
 AllSettings::AllSettings()
+: mpData(boost::make_shared<ImplAllSettingsData>())
 {
-
-    mpData = new ImplAllSettingsData();
 }
 
 // -----------------------------------------------------------------------
 
 AllSettings::AllSettings( const AllSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "Settings: RefCount 
overflow" );
-
-    // copy shared instance data and increse reference counter
     mpData = rSet.mpData;
-    mpData->mnRefCount++;
 }
 
 // -----------------------------------------------------------------------
 
 AllSettings::~AllSettings()
 {
-
-    // if last reference then delete data
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
 }
 
 // -----------------------------------------------------------------------
 
 const AllSettings& AllSettings::operator =( const AllSettings& rSet )
 {
-    DBG_ASSERT( rSet.mpData->mnRefCount < 0xFFFFFFFE, "AllSettings: RefCount 
overflow" );
-
-    // increase reference counter first, to be able to assign oneself
-    rSet.mpData->mnRefCount++;
-
-    // if last reference then delete data
-    if ( mpData->mnRefCount == 1 )
-        delete mpData;
-    else
-        mpData->mnRefCount--;
-
     mpData = rSet.mpData;
-
     return *this;
 }
 
@@ -1452,13 +1330,11 @@ const AllSettings& AllSettings::operator =( const 
AllSettings& rSet )
 
 void AllSettings::CopyData()
 {
-
     // copy if other references exist
-    if ( mpData->mnRefCount != 1 )
-    {
-        mpData->mnRefCount--;
-        mpData = new ImplAllSettingsData( *mpData );
+    if ( ! mpData.unique() ) {
+        mpData = boost::make_shared<ImplAllSettingsData>(*mpData);
     }
+
 }
 
 // -----------------------------------------------------------------------
@@ -1747,4 +1623,16 @@ void AllSettings::LocaleSettingsChanged( sal_uInt32 
nHint )
     Application::SetSettings( aAllSettings );
 }
 
+const StyleSettings&
+AllSettings::GetStyleSettings() const
+{
+    return mpData->maStyleSettings;
+}
+
+sal_uLong
+StyleSettings::GetOptions() const
+{
+    return mpData->mnOptions;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to