diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-02-23 10:37:09 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-02-23 10:47:37 +0100 |
commit | 2eaa1422a032d6a7ffc72a2abeb3dd3e6248a263 (patch) | |
tree | a8a618394c09b21cd189a4f9f221557dc5fc628a | |
parent | 40d21ab3c75a7c18de940162563015ae80136709 (diff) |
Adapted AsyncEventNotifier to safer-to-use salhelper::Thread
-rw-r--r-- | comphelper/Library_comphelp.mk | 5 | ||||
-rw-r--r-- | comphelper/inc/comphelper/asyncnotification.hxx | 33 | ||||
-rw-r--r-- | comphelper/prj/build.lst | 2 | ||||
-rw-r--r-- | comphelper/source/misc/asyncnotification.cxx | 37 | ||||
-rw-r--r-- | dbaccess/source/core/dataaccess/documenteventnotifier.cxx | 9 | ||||
-rw-r--r-- | extensions/Library_pcr.mk | 1 | ||||
-rw-r--r-- | extensions/prj/build.lst | 2 | ||||
-rw-r--r-- | extensions/source/propctrlr/browserlistbox.cxx | 9 | ||||
-rw-r--r-- | forms/Library_frm.mk | 1 | ||||
-rw-r--r-- | forms/prj/build.lst | 2 | ||||
-rw-r--r-- | forms/source/component/ListBox.cxx | 11 |
11 files changed, 46 insertions, 66 deletions
diff --git a/comphelper/Library_comphelp.mk b/comphelper/Library_comphelp.mk index 2b37596b0bcf..71ef2a01b9b2 100644 --- a/comphelper/Library_comphelp.mk +++ b/comphelper/Library_comphelp.mk @@ -42,9 +42,10 @@ $(eval $(call gb_Library_add_defs,comphelper,\ )) $(eval $(call gb_Library_add_linked_libs,comphelper,\ - sal \ - cppuhelper \ cppu \ + cppuhelper \ + sal \ + salhelper \ ucbhelper \ $(gb_STDLIBS) \ )) diff --git a/comphelper/inc/comphelper/asyncnotification.hxx b/comphelper/inc/comphelper/asyncnotification.hxx index e7d5ac38ff3b..0ca35a3bf2a5 100644 --- a/comphelper/inc/comphelper/asyncnotification.hxx +++ b/comphelper/inc/comphelper/asyncnotification.hxx @@ -29,12 +29,13 @@ #ifndef COMPHELPER_ASYNCNOTIFICATION_HXX #define COMPHELPER_ASYNCNOTIFICATION_HXX -#include <osl/thread.hxx> -#include <rtl/ref.hxx> -#include <comphelper/comphelperdllapi.h> -#include <rtl/alloc.h> +#include "sal/config.h" -#include <memory> +#include "boost/scoped_ptr.hpp" +#include "comphelper/comphelperdllapi.h" +#include "rtl/ref.hxx" +#include "sal/types.h" +#include "salhelper/thread.hxx" //........................................................................ namespace comphelper @@ -109,26 +110,25 @@ namespace comphelper events in the queue. As soon as you add an event, the thread is woken up, processes the event, and sleeps again. */ - class COMPHELPER_DLLPUBLIC AsyncEventNotifier :public ::osl::Thread - ,public ::rtl::IReference + class COMPHELPER_DLLPUBLIC AsyncEventNotifier: public salhelper::Thread { friend struct EventNotifierImpl; private: - ::std::auto_ptr< EventNotifierImpl > m_pImpl; + boost::scoped_ptr< EventNotifierImpl > m_pImpl; + + SAL_DLLPRIVATE virtual ~AsyncEventNotifier(); // Thread - virtual void SAL_CALL run(); - virtual void SAL_CALL onTerminated(); + SAL_DLLPRIVATE virtual void execute(); public: /** constructs a notifier thread - */ - AsyncEventNotifier(); - // IReference implementations - virtual oslInterlockedCount SAL_CALL acquire(); - virtual oslInterlockedCount SAL_CALL release(); + @param name the thread name, see ::osl_setThreadName; must not be + null + */ + AsyncEventNotifier(char const * name); /** terminates the thread @@ -156,9 +156,6 @@ namespace comphelper /** removes all events for the given event processor from the queue */ void removeEventsForProcessor( const ::rtl::Reference< IEventProcessor >& _xProcessor ); - - protected: - virtual ~AsyncEventNotifier(); }; //==================================================================== diff --git a/comphelper/prj/build.lst b/comphelper/prj/build.lst index 722ac8161de6..007c0472ea81 100644 --- a/comphelper/prj/build.lst +++ b/comphelper/prj/build.lst @@ -1,2 +1,2 @@ -ph comphelper : cppuhelper ucbhelper offapi officecfg salhelper LIBXSLT:libxslt NULL +ch comphelper : BOOST:boost cppuhelper ucbhelper offapi officecfg salhelper LIBXSLT:libxslt NULL ch comphelper\prj nmake - all ch_all NULL diff --git a/comphelper/source/misc/asyncnotification.cxx b/comphelper/source/misc/asyncnotification.cxx index cf8b6286d97b..216cdb2f765f 100644 --- a/comphelper/source/misc/asyncnotification.cxx +++ b/comphelper/source/misc/asyncnotification.cxx @@ -142,8 +142,8 @@ namespace comphelper //= AsyncEventNotifier //==================================================================== //-------------------------------------------------------------------- - AsyncEventNotifier::AsyncEventNotifier() - :m_pImpl( new EventNotifierImpl ) + AsyncEventNotifier::AsyncEventNotifier(char const * name): + Thread(name), m_pImpl(new EventNotifierImpl) { } @@ -191,13 +191,8 @@ namespace comphelper } //-------------------------------------------------------------------- - void AsyncEventNotifier::run() + void AsyncEventNotifier::execute() { - acquire(); - - // keep us alive, in case we're terminated in the mid of the following - ::rtl::Reference< AsyncEventNotifier > xKeepAlive( this ); - do { AnyEventRef aNextEvent; @@ -248,32 +243,6 @@ namespace comphelper while ( sal_True ); } - //-------------------------------------------------------------------- - void SAL_CALL AsyncEventNotifier::onTerminated() - { - Thread::onTerminated(); - // when we were started (->run), we aquired ourself. Release this now - // that we were finally terminated - release(); - } - - //-------------------------------------------------------------------- - oslInterlockedCount SAL_CALL AsyncEventNotifier::acquire() - { - return osl_incrementInterlockedCount( &m_pImpl->m_refCount ); - } - - //-------------------------------------------------------------------- - oslInterlockedCount SAL_CALL AsyncEventNotifier::release() - { - if ( 0 == osl_decrementInterlockedCount( &m_pImpl->m_refCount ) ) - { - delete this; - return 0; - } - return m_pImpl->m_refCount; - } - //........................................................................ } // namespace comphelper //........................................................................ diff --git a/dbaccess/source/core/dataaccess/documenteventnotifier.cxx b/dbaccess/source/core/dataaccess/documenteventnotifier.cxx index 24a46a2e776d..2b7cf9ba33cb 100644 --- a/dbaccess/source/core/dataaccess/documenteventnotifier.cxx +++ b/dbaccess/source/core/dataaccess/documenteventnotifier.cxx @@ -166,7 +166,7 @@ namespace dbaccess m_pEventBroadcaster->removeEventsForProcessor( this ); m_pEventBroadcaster->terminate(); m_pEventBroadcaster->join(); - m_pEventBroadcaster = NULL; + m_pEventBroadcaster.clear(); } lang::EventObject aEvent( m_rDocument ); @@ -190,7 +190,7 @@ namespace dbaccess m_bInitialized = true; if ( m_pEventBroadcaster.is() ) // there are already pending asynchronous events - m_pEventBroadcaster->create(); + m_pEventBroadcaster->launch(); } void DocumentEventNotifier_Impl::impl_notifyEvent_nothrow( const DocumentEvent& _rEvent ) @@ -220,11 +220,12 @@ namespace dbaccess { if ( !m_pEventBroadcaster.is() ) { - m_pEventBroadcaster.set( new ::comphelper::AsyncEventNotifier ); + m_pEventBroadcaster.set( + new ::comphelper::AsyncEventNotifier("DocumentEventNotifier")); if ( m_bInitialized ) // start processing the events if and only if we (our document, respectively) are // already initialized - m_pEventBroadcaster->create(); + m_pEventBroadcaster->launch(); } m_pEventBroadcaster->addEvent( new DocumentEventHolder( _rEvent ), this ); } diff --git a/extensions/Library_pcr.mk b/extensions/Library_pcr.mk index 857258d7b9d9..2a32152e6809 100644 --- a/extensions/Library_pcr.mk +++ b/extensions/Library_pcr.mk @@ -57,6 +57,7 @@ $(eval $(call gb_Library_add_linked_libs,pcr,\ cppuhelper \ cppu \ sal \ + salhelper \ $(gb_STDLIBS) \ )) diff --git a/extensions/prj/build.lst b/extensions/prj/build.lst index 06f2e2de9a66..90e646afbf81 100644 --- a/extensions/prj/build.lst +++ b/extensions/prj/build.lst @@ -1,4 +1,4 @@ -ex extensions : officecfg TRANSLATIONS:translations DESKTOP:rdbmaker svx SANE:sane TWAIN:twain np_sdk offapi stoc ZLIB:zlib CURL:curl LIBXSLT:libxslt CPPUNIT:cppunit NULL +ex extensions : officecfg salhelper TRANSLATIONS:translations DESKTOP:rdbmaker svx SANE:sane TWAIN:twain np_sdk offapi stoc ZLIB:zlib CURL:curl LIBXSLT:libxslt CPPUNIT:cppunit NULL ex extensions\prj nmake - all ex_prj NULL # Fails at the moment diff --git a/extensions/source/propctrlr/browserlistbox.cxx b/extensions/source/propctrlr/browserlistbox.cxx index 0abddac638db..ec907ab4caff 100644 --- a/extensions/source/propctrlr/browserlistbox.cxx +++ b/extensions/source/propctrlr/browserlistbox.cxx @@ -126,8 +126,13 @@ namespace pcr ::osl::MutexGuard aGuard( getMutex() ); if ( !s_pNotifier.is() ) { - s_pNotifier.set( new ::comphelper::AsyncEventNotifier ); - s_pNotifier->create(); + s_pNotifier.set( + new ::comphelper::AsyncEventNotifier("browserlistbox")); + s_pNotifier->launch(); + //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 } return s_pNotifier; } diff --git a/forms/Library_frm.mk b/forms/Library_frm.mk index f6558ef2f9a0..f38dd3bd2701 100644 --- a/forms/Library_frm.mk +++ b/forms/Library_frm.mk @@ -47,6 +47,7 @@ $(eval $(call gb_Library_add_linked_libs,frm,\ editeng \ i18nisolang1 \ sal \ + salhelper \ sfx \ svl \ svt \ diff --git a/forms/prj/build.lst b/forms/prj/build.lst index 131e8e406034..599b6c7de5e7 100644 --- a/forms/prj/build.lst +++ b/forms/prj/build.lst @@ -1,4 +1,4 @@ -fm forms : TRANSLATIONS:translations oovbaapi svx sfx2 QADEVOOO:qadevOOo LIBXSLT:libxslt NULL +fm forms : TRANSLATIONS:translations oovbaapi salhelper svx sfx2 QADEVOOO:qadevOOo LIBXSLT:libxslt NULL fm forms usr1 - all fm_mkofrm NULL fm forms\prj nmake - all fm_prj NULL diff --git a/forms/source/component/ListBox.cxx b/forms/source/component/ListBox.cxx index eb8c6c9b037b..5dbf8a857f56 100644 --- a/forms/source/component/ListBox.cxx +++ b/forms/source/component/ListBox.cxx @@ -1528,7 +1528,6 @@ namespace frm :OBoundControl( _rxFactory, VCL_CONTROL_LISTBOX, sal_False ) ,m_aChangeListeners( m_aMutex ) ,m_aItemListeners( m_aMutex ) - ,m_pItemBroadcaster( NULL ) { DBG_CTOR(OListBoxControl,NULL); @@ -1614,8 +1613,9 @@ namespace frm { if ( !m_pItemBroadcaster.is() ) { - m_pItemBroadcaster.set( new ::comphelper::AsyncEventNotifier ); - m_pItemBroadcaster->create(); + m_pItemBroadcaster.set( + new ::comphelper::AsyncEventNotifier("ListBox")); + m_pItemBroadcaster->launch(); } m_pItemBroadcaster->addEvent( new ItemEventDescription( _rEvent ), this ); } @@ -1701,15 +1701,20 @@ namespace frm m_aChangeListeners.disposeAndClear( aEvent ); m_aItemListeners.disposeAndClear( aEvent ); + rtl::Reference< comphelper::AsyncEventNotifier > t; { ::osl::MutexGuard aGuard( m_aMutex ); if ( m_pItemBroadcaster.is() ) { + t = m_pItemBroadcaster; m_pItemBroadcaster->removeEventsForProcessor( this ); m_pItemBroadcaster->terminate(); m_pItemBroadcaster = NULL; } } + if (t.is()) { + t->join(); + } OBoundControl::disposing(); } |