Kaydet (Commit) b5764eb9 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Adapted FileViewContentEnumerator to safer-to-use salhelper::Thread

üst 2eaa1422
...@@ -94,7 +94,8 @@ namespace svt ...@@ -94,7 +94,8 @@ namespace svt
const Reference< XCommandEnvironment >& _rxCommandEnv, const Reference< XCommandEnvironment >& _rxCommandEnv,
ContentData& _rContentToFill, ::osl::Mutex& _rContentMutex, ContentData& _rContentToFill, ::osl::Mutex& _rContentMutex,
const IContentTitleTranslation* _pTranslator ) const IContentTitleTranslation* _pTranslator )
:m_rContent ( _rContentToFill ) :Thread ( "FileViewContentEnumerator" )
,m_rContent ( _rContentToFill )
,m_rContentMutex ( _rContentMutex ) ,m_rContentMutex ( _rContentMutex )
,m_refCount ( 0 ) ,m_refCount ( 0 )
,m_xCommandEnv ( _rxCommandEnv ) ,m_xCommandEnv ( _rxCommandEnv )
...@@ -142,15 +143,6 @@ namespace svt ...@@ -142,15 +143,6 @@ namespace svt
void FileViewContentEnumerator::enumerateFolderContent( void FileViewContentEnumerator::enumerateFolderContent(
const FolderDescriptor& _rFolder, const IUrlFilter* _pFilter, IEnumerationResultHandler* _pResultHandler ) const FolderDescriptor& _rFolder, const IUrlFilter* _pFilter, IEnumerationResultHandler* _pResultHandler )
{ {
// ensure that we don't get deleted while herein
acquire();
// the matching "release" will be called in onTerminated
// Note that onTerminated is only called if run was left normally.
// If somebody terminates the thread from the outside, then onTerminated
// will never be called. However, our terminate method is not accessible
// to our clients, so the only class which could misbehave is this class
// here itself ...
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
m_aFolder = _rFolder; m_aFolder = _rFolder;
m_pFilter = _pFilter; m_pFilter = _pFilter;
...@@ -159,25 +151,11 @@ namespace svt ...@@ -159,25 +151,11 @@ namespace svt
OSL_ENSURE( m_aFolder.aContent.get().is() || m_aFolder.sURL.Len(), OSL_ENSURE( m_aFolder.aContent.get().is() || m_aFolder.sURL.Len(),
"FileViewContentEnumerator::enumerateFolderContent: invalid folder descriptor!" ); "FileViewContentEnumerator::enumerateFolderContent: invalid folder descriptor!" );
// start the thread launch();
create(); //TODO: a protocol is missing how to join with the launched thread
} // before exit(3), to ensure the thread is no longer relying on any
// infrastructure while that infrastructure is being shut down in
//-------------------------------------------------------------------- // atexit handlers
oslInterlockedCount SAL_CALL FileViewContentEnumerator::acquire()
{
return osl_incrementInterlockedCount( &m_refCount );
}
//--------------------------------------------------------------------
oslInterlockedCount SAL_CALL FileViewContentEnumerator::release()
{
if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
{
delete this;
return 0;
}
return m_refCount;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
...@@ -446,17 +424,11 @@ namespace svt ...@@ -446,17 +424,11 @@ namespace svt
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void SAL_CALL FileViewContentEnumerator::run() void FileViewContentEnumerator::execute()
{ {
enumerateFolderContent(); enumerateFolderContent();
} }
//--------------------------------------------------------------------
void SAL_CALL FileViewContentEnumerator::onTerminated()
{
release();
}
//........................................................................ //........................................................................
} // namespace svt } // namespace svt
//........................................................................ //........................................................................
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include <com/sun/star/ucb/XCommandEnvironment.hpp> #include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <com/sun/star/document/XStandaloneDocumentInfo.hpp> #include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
/** === end UNO includes === **/ /** === end UNO includes === **/
#include <osl/thread.hxx> #include <salhelper/thread.hxx>
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
#include <ucbhelper/content.hxx> #include <ucbhelper/content.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
...@@ -185,9 +185,7 @@ namespace svt ...@@ -185,9 +185,7 @@ namespace svt
//==================================================================== //====================================================================
//= FileViewContentEnumerator //= FileViewContentEnumerator
//==================================================================== //====================================================================
class FileViewContentEnumerator class FileViewContentEnumerator: public salhelper::Thread
:public ::rtl::IReference
,private ::osl::Thread
{ {
public: public:
typedef ::std::vector< SortingData_Impl* > ContentData; typedef ::std::vector< SortingData_Impl* > ContentData;
...@@ -261,13 +259,6 @@ namespace svt ...@@ -261,13 +259,6 @@ namespace svt
*/ */
void cancel(); void cancel();
// IReference overridables
virtual oslInterlockedCount SAL_CALL acquire();
virtual oslInterlockedCount SAL_CALL release();
using Thread::operator new;
using Thread::operator delete;
protected: protected:
~FileViewContentEnumerator(); ~FileViewContentEnumerator();
...@@ -275,8 +266,7 @@ namespace svt ...@@ -275,8 +266,7 @@ namespace svt
EnumerationResult enumerateFolderContent(); EnumerationResult enumerateFolderContent();
// Thread overridables // Thread overridables
virtual void SAL_CALL run(); virtual void execute();
virtual void SAL_CALL onTerminated();
private: private:
sal_Bool implGetDocTitle( const ::rtl::OUString& _rTargetURL, ::rtl::OUString& _rRet ) const; sal_Bool implGetDocTitle( const ::rtl::OUString& _rTargetURL, ::rtl::OUString& _rRet ) const;
......
...@@ -1865,10 +1865,10 @@ FileViewResult SvtFileView_Impl::GetFolderContent_Impl( ...@@ -1865,10 +1865,10 @@ FileViewResult SvtFileView_Impl::GetFolderContent_Impl(
if ( ::svt::SUCCESS == eResult ) if ( ::svt::SUCCESS == eResult )
{ {
implEnumerationSuccess(); implEnumerationSuccess();
m_pContentEnumerator = NULL; m_pContentEnumerator.clear();
return eSuccess; return eSuccess;
} }
m_pContentEnumerator = NULL; m_pContentEnumerator.clear();
return eFailure; return eFailure;
} }
...@@ -2126,7 +2126,7 @@ void SvtFileView_Impl::CancelRunningAsyncAction() ...@@ -2126,7 +2126,7 @@ void SvtFileView_Impl::CancelRunningAsyncAction()
m_pContentEnumerator->cancel(); m_pContentEnumerator->cancel();
m_bRunningAsyncAction = false; m_bRunningAsyncAction = false;
m_pContentEnumerator = NULL; m_pContentEnumerator.clear();
if ( m_pCancelAsyncTimer.is() && m_pCancelAsyncTimer->isTicking() ) if ( m_pCancelAsyncTimer.is() && m_pCancelAsyncTimer->isTicking() )
m_pCancelAsyncTimer->stop(); m_pCancelAsyncTimer->stop();
m_pCancelAsyncTimer = NULL; m_pCancelAsyncTimer = NULL;
...@@ -2156,7 +2156,7 @@ void SvtFileView_Impl::enumerationDone( ::svt::EnumerationResult _eResult ) ...@@ -2156,7 +2156,7 @@ void SvtFileView_Impl::enumerationDone( ::svt::EnumerationResult _eResult )
SolarMutexGuard aSolarGuard; SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( maMutex ); ::osl::MutexGuard aGuard( maMutex );
m_pContentEnumerator = NULL; m_pContentEnumerator.clear();
if ( m_pCancelAsyncTimer.is() && m_pCancelAsyncTimer->isTicking() ) if ( m_pCancelAsyncTimer.is() && m_pCancelAsyncTimer->isTicking() )
m_pCancelAsyncTimer->stop(); m_pCancelAsyncTimer->stop();
m_pCancelAsyncTimer = NULL; m_pCancelAsyncTimer = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment