[Libreoffice-commits] core.git: vcl/headless vcl/inc

Stephan Bergmann sbergman at redhat.com
Fri Jan 22 06:00:21 PST 2016


 vcl/headless/svpinst.cxx     |   36 ++++++++++++++----------------------
 vcl/inc/headless/svpinst.hxx |    2 +-
 2 files changed, 15 insertions(+), 23 deletions(-)

New commits:
commit dfbc2f37207f11a3bafb2c5ce0dea4fcc137e527
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Jan 22 14:58:48 2016 +0100

    Use C++ osl::Mutex, osl::MutexGuard
    
    ...and get rid of that curious "defensive programming" mis-handling of a failing
    osl_acquireMutex
    
    Change-Id: I1730c2d8334f0137ee8646ab990d0914426246bb

diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
index 5e3ffdf..50f0705 100644
--- a/vcl/headless/svpinst.cxx
+++ b/vcl/headless/svpinst.cxx
@@ -96,7 +96,6 @@ SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) :
             (void)fcntl(m_pTimeoutFDS[1], F_SETFL, flags);
         }
     }
-    m_aEventGuard = osl_createMutex();
     if( s_pDefaultInstance == nullptr )
         s_pDefaultInstance = this;
 }
@@ -109,15 +108,13 @@ SvpSalInstance::~SvpSalInstance()
     // close 'wakeup' pipe.
     close (m_pTimeoutFDS[0]);
     close (m_pTimeoutFDS[1]);
-    osl_destroyMutex( m_aEventGuard );
 }
 
 void SvpSalInstance::PostEvent(const SalFrame* pFrame, ImplSVEvent* pData, sal_uInt16 nEvent)
 {
-    if( osl_acquireMutex( m_aEventGuard ) )
     {
+        osl::MutexGuard g(m_aEventGuard);
         m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
-        osl_releaseMutex( m_aEventGuard );
     }
     Wakeup();
 }
@@ -126,10 +123,9 @@ void SvpSalInstance::PostEvent(const SalFrame* pFrame, ImplSVEvent* pData, sal_u
 bool SvpSalInstance::PostedEventsInQueue()
 {
     bool result = false;
-    if( osl_acquireMutex( m_aEventGuard ) )
     {
+        osl::MutexGuard g(m_aEventGuard);
         result = m_aUserEvents.size() > 0;
-        osl_releaseMutex( m_aEventGuard );
     }
     return result;
 }
@@ -139,23 +135,20 @@ void SvpSalInstance::deregisterFrame( SalFrame* pFrame )
 {
     m_aFrames.remove( pFrame );
 
-    if( osl_acquireMutex( m_aEventGuard ) )
+    osl::MutexGuard g(m_aEventGuard);
+    // cancel outstanding events for this frame
+    if( ! m_aUserEvents.empty() )
     {
-        // cancel outstanding events for this frame
-        if( ! m_aUserEvents.empty() )
+        std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
+        do
         {
-            std::list< SalUserEvent >::iterator it = m_aUserEvents.begin();
-            do
+            if( it->m_pFrame    == pFrame )
             {
-                if( it->m_pFrame    == pFrame )
-                {
-                    it = m_aUserEvents.erase( it );
-                }
-                else
-                    ++it;
-            } while( it != m_aUserEvents.end() );
-        }
-        osl_releaseMutex( m_aEventGuard );
+                it = m_aUserEvents.erase( it );
+            }
+            else
+                ++it;
+        } while( it != m_aUserEvents.end() );
     }
 }
 
@@ -267,8 +260,8 @@ SalYieldResult SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents,
     // release yield mutex
     std::list< SalUserEvent > aEvents;
     sal_uLong nAcquireCount = ReleaseYieldMutex();
-    if( osl_acquireMutex( m_aEventGuard ) )
     {
+        osl::MutexGuard g(m_aEventGuard);
         if( ! m_aUserEvents.empty() )
         {
             if( bHandleAllCurrentEvents )
@@ -282,7 +275,6 @@ SalYieldResult SvpSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents,
                 m_aUserEvents.pop_front();
             }
         }
-        osl_releaseMutex( m_aEventGuard );
     }
     // acquire yield mutex again
     AcquireYieldMutex( nAcquireCount );
diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx
index 417afd8..1505a3b 100644
--- a/vcl/inc/headless/svpinst.hxx
+++ b/vcl/inc/headless/svpinst.hxx
@@ -77,7 +77,7 @@ class VCL_DLLPUBLIC SvpSalInstance : public SalGenericInstance
         {}
     };
 
-    oslMutex                m_aEventGuard;
+    osl::Mutex              m_aEventGuard;
     std::list< SalUserEvent > m_aUserEvents;
 
     std::list< SalFrame* >  m_aFrames;


More information about the Libreoffice-commits mailing list