[Libreoffice-commits] .: tools/source

Joseph Powers jpowers at kemper.freedesktop.org
Wed Feb 16 06:26:19 PST 2011


 tools/source/stream/strmunx.cxx |   47 +++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 17 deletions(-)

New commits:
commit fa0c91f700c90d6b5e4201c07cf7c698e471f1a5
Author: Joseph Powers <jpowers27 at cox.net>
Date:   Wed Feb 16 06:26:02 2011 -0800

    Remove DECLARE_LIST( InternalStreamLockList, InternalStreamLock* )

diff --git a/tools/source/stream/strmunx.cxx b/tools/source/stream/strmunx.cxx
index ec9b20b..ed27d7a 100644
--- a/tools/source/stream/strmunx.cxx
+++ b/tools/source/stream/strmunx.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -26,7 +26,7 @@
  *
  ************************************************************************/
 
-// no include "precompiled_tools.hxx" because this file is included in strmsys.cxx
+// don't include "precompiled_tools.hxx" because this file is included in strmsys.cxx
 
 #include <stdio.h>
 #include <string.h>
@@ -40,6 +40,7 @@
 #include <tools/debug.hxx>
 #include <tools/fsys.hxx>
 #include <tools/stream.hxx>
+#include <vector>
 
 #include <osl/mutex.hxx>
 #include <osl/thread.h> // osl_getThreadTextEncoding
@@ -56,10 +57,6 @@ using namespace osl;
 // - InternalLock -
 // ----------------
 
-class InternalStreamLock;
-DECLARE_LIST( InternalStreamLockList, InternalStreamLock* )
-namespace { struct LockList : public rtl::Static< InternalStreamLockList, LockList > {}; }
-
 #ifndef BOOTSTRAP
 namespace { struct LockMutex : public rtl::Static< osl::Mutex, LockMutex > {}; }
 #endif
@@ -78,6 +75,9 @@ public:
     static void UnlockFile( sal_Size nStart, sal_Size nEnd, SvFileStream* );
 };
 
+typedef ::std::vector< InternalStreamLock* > InternalStreamLockList;
+namespace { struct LockList : public rtl::Static< InternalStreamLockList, LockList > {}; }
+
 InternalStreamLock::InternalStreamLock(
     sal_Size nStart,
     sal_Size nEnd,
@@ -88,7 +88,7 @@ InternalStreamLock::InternalStreamLock(
 {
     ByteString aFileName(m_pStream->GetFileName(), osl_getThreadTextEncoding());
     stat( aFileName.GetBuffer(), &m_aStat );
-    LockList::get().Insert( this, LIST_APPEND );
+    LockList::get().push_back( this );
 #if OSL_DEBUG_LEVEL > 1
     fprintf( stderr, "locked %s", aFileName.GetBuffer() );
     if( m_nStartPos || m_nEndPos )
@@ -99,7 +99,15 @@ InternalStreamLock::InternalStreamLock(
 
 InternalStreamLock::~InternalStreamLock()
 {
-    LockList::get().Remove( this );
+    for ( InternalStreamLockList::iterator it = LockList::get().begin();
+          it < LockList::get().end();
+          ++it
+    ) {
+        if ( this == *it ) {
+            LockList::get().erase( it );
+            break;
+        }
+    }
 #if OSL_DEBUG_LEVEL > 1
     ByteString aFileName(m_pStream->GetFileName(), osl_getThreadTextEncoding());
     fprintf( stderr, "unlocked %s", aFileName.GetBuffer() );
@@ -124,9 +132,9 @@ sal_Bool InternalStreamLock::LockFile( sal_Size nStart, sal_Size nEnd, SvFileStr
 
     InternalStreamLock* pLock = NULL;
     InternalStreamLockList &rLockList = LockList::get();
-    for( ULONG i = 0; i < rLockList.Count(); ++i )
+    for( size_t i = 0; i < rLockList.size(); ++i )
     {
-        pLock = rLockList.GetObject( i );
+        pLock = rLockList[ i ];
         if( aStat.st_ino == pLock->m_aStat.st_ino )
         {
             sal_Bool bDenyByOptions = sal_False;
@@ -155,6 +163,7 @@ sal_Bool InternalStreamLock::LockFile( sal_Size nStart, sal_Size nEnd, SvFileStr
             }
         }
     }
+    // hint: new InternalStreamLock() adds the entry to the global list
     pLock  = new InternalStreamLock( nStart, nEnd, pStream );
     return sal_True;
 }
@@ -168,27 +177,32 @@ void InternalStreamLock::UnlockFile( sal_Size nStart, sal_Size nEnd, SvFileStrea
     InternalStreamLockList &rLockList = LockList::get();
     if( nStart == 0 && nEnd == 0 )
     {
-        for( ULONG i = 0; i < rLockList.Count(); ++i )
+        // nStart & nEnd = 0, so delete all locks
+        for( size_t i = 0; i < rLockList.size(); ++i )
         {
-            if( ( pLock = rLockList.GetObject( i ) )->m_pStream == pStream )
+            if( ( pLock = rLockList[ i ] )->m_pStream == pStream )
             {
+                // hint: delete will remove pLock from the global list
                 delete pLock;
                 i--;
             }
         }
         return;
     }
-    for( ULONG i = 0; i < rLockList.Count(); ++i )
+    for( size_t i = 0; i < rLockList.size(); ++i )
     {
-        if( ( pLock = rLockList.GetObject( i ) )->m_pStream == pStream &&
-            nStart == pLock->m_nStartPos && nEnd == pLock->m_nEndPos )
-        {
+        if (  ( pLock = rLockList[ i ] )->m_pStream == pStream
+           && nStart == pLock->m_nStartPos
+           && nEnd == pLock->m_nEndPos
+        ) {
+            // hint: delete will remove pLock from the global list
             delete pLock;
             return;
         }
     }
 }
 
+
 // --------------
 // - StreamData -
 // --------------
@@ -846,5 +860,4 @@ void SvFileStream::SetSize (sal_Size nSize)
     }
 }
 
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list