From b47ae754c94a6cea4aa61da4072db97ac9fdfd7c Mon Sep 17 00:00:00 2001 From: Tino Rachui Date: Tue, 26 Nov 2002 08:21:59 +0000 Subject: #105339#support for suspend and resume of event notifier thread --- fpicker/source/win32/filepicker/FilePicker.cxx | 48 ++++++++++++++++-- fpicker/source/win32/filepicker/FilePicker.hxx | 9 +++- .../source/win32/filepicker/asynceventnotifier.cxx | 58 ++++++++++++++++++---- .../source/win32/filepicker/asynceventnotifier.hxx | 21 ++++++-- 4 files changed, 116 insertions(+), 20 deletions(-) (limited to 'fpicker') diff --git a/fpicker/source/win32/filepicker/FilePicker.cxx b/fpicker/source/win32/filepicker/FilePicker.cxx index e2baed55e1d5..c52e96dcacee 100644 --- a/fpicker/source/win32/filepicker/FilePicker.cxx +++ b/fpicker/source/win32/filepicker/FilePicker.cxx @@ -2,9 +2,9 @@ * * $RCSfile: FilePicker.cxx,v $ * - * $Revision: 1.17 $ + * $Revision: 1.18 $ * - * last change: $Author: tra $ $Date: 2002-03-28 08:57:33 $ + * last change: $Author: tra $ $Date: 2002-11-26 09:21:59 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -115,6 +115,10 @@ using namespace ::com::sun::star::ui::dialogs::TemplateDescription; namespace { + // controling event notifications + const bool STARTUP_SUSPENDED = true; + const bool STARTUP_ALIVE = false; + uno::Sequence SAL_CALL FilePicker_getSupportedServiceNames() { uno::Sequence aRet(2); @@ -287,6 +291,42 @@ rtl::OUString SAL_CALL CFilePicker::helpRequested(FilePickerEvent aEvent) const return aHelpText; } +//------------------------------------- +// +//------------------------------------- + +bool CFilePicker::startupEventNotification(bool bStartupSuspended) +{ + return m_aAsyncEventNotifier.startup(bStartupSuspended); +} + +//------------------------------------- +// +//------------------------------------- + +void CFilePicker::shutdownEventNotification() +{ + m_aAsyncEventNotifier.shutdown(); +} + +//------------------------------------- +// +//------------------------------------- + +void CFilePicker::suspendEventNotification() +{ + m_aAsyncEventNotifier.suspend(); +} + +//------------------------------------- +// +//------------------------------------- + +void CFilePicker::resumeEventNotification() +{ + m_aAsyncEventNotifier.resume(); +} + //------------------------------------------------------------------------------------ // XFilePicker functions //------------------------------------------------------------------------------------ @@ -412,7 +452,7 @@ sal_Int16 SAL_CALL CFilePicker::execute() throw(uno::RuntimeException) sal_Int16 ret; - if (m_aAsyncEventNotifier.start()) + if (startupEventNotification(STARTUP_SUSPENDED)) { // we should not block in this call else // in the case of an event the client can't @@ -420,7 +460,7 @@ sal_Int16 SAL_CALL CFilePicker::execute() throw(uno::RuntimeException) // deadlock !!!!! ret = m_pImpl->execute( ); - m_aAsyncEventNotifier.stop(); + shutdownEventNotification(); } else { diff --git a/fpicker/source/win32/filepicker/FilePicker.hxx b/fpicker/source/win32/filepicker/FilePicker.hxx index 3a82db79c262..e59a7e0cb979 100644 --- a/fpicker/source/win32/filepicker/FilePicker.hxx +++ b/fpicker/source/win32/filepicker/FilePicker.hxx @@ -2,9 +2,9 @@ * * $RCSfile: FilePicker.hxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: tra $ $Date: 2002-03-28 08:57:33 $ + * last change: $Author: tra $ $Date: 2002-11-26 09:21:59 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -294,6 +294,11 @@ public: void SAL_CALL controlStateChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ); void SAL_CALL dialogSizeChanged( ); + bool startupEventNotification(bool bStartupSuspended); + void shutdownEventNotification(); + void suspendEventNotification(); + void resumeEventNotification(); + private: // prevent copy and assignment CFilePicker( const CFilePicker& ); diff --git a/fpicker/source/win32/filepicker/asynceventnotifier.cxx b/fpicker/source/win32/filepicker/asynceventnotifier.cxx index 763d5f4e5830..51cc2e8a86af 100644 --- a/fpicker/source/win32/filepicker/asynceventnotifier.cxx +++ b/fpicker/source/win32/filepicker/asynceventnotifier.cxx @@ -2,9 +2,9 @@ * * $RCSfile: asynceventnotifier.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: tra $ $Date: 2002-03-28 08:57:33 $ + * last change: $Author: tra $ $Date: 2002-11-26 09:21:59 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -97,8 +97,21 @@ CAsyncEventNotifier::CAsyncEventNotifier(cppu::OBroadcastHelper& rBroadcastHelpe m_hThread(0), m_bRun(false), m_ThreadId(0), - m_rBroadcastHelper(rBroadcastHelper) + m_rBroadcastHelper(rBroadcastHelper), + m_NotifyEvent(m_hEvents[0]), + m_ResumeNotifying(m_hEvents[1]) { + // m_NotifyEvent + m_hEvents[0] = CreateEvent(0, /* no security */ + true, /* manual reset */ + false, /* initial state not signaled */ + 0); /* automatic name */ + + // m_ResumeNotifying + m_hEvents[1] = CreateEvent(0, /* no security */ + true, /* manual reset */ + false, /* initial state not signaled */ + 0); /* automatic name */ } //------------------------------------------------ @@ -108,13 +121,16 @@ CAsyncEventNotifier::CAsyncEventNotifier(cppu::OBroadcastHelper& rBroadcastHelpe CAsyncEventNotifier::~CAsyncEventNotifier() { OSL_ENSURE(0 == m_hThread,"Thread not stopped, destroying this instance leads to desaster"); + + CloseHandle(m_hEvents[0]); + CloseHandle(m_hEvents[1]); } //------------------------------------------------ // //------------------------------------------------ -bool SAL_CALL CAsyncEventNotifier::start() +bool SAL_CALL CAsyncEventNotifier::startup(bool bCreateSuspended) { osl::MutexGuard aGuard(m_Mutex); @@ -125,6 +141,9 @@ bool SAL_CALL CAsyncEventNotifier::start() // not be overwritten if (!m_bRun) { + if (!bCreateSuspended) + SetEvent(m_ResumeNotifying); + m_hThread = (HANDLE)_beginthreadex( NULL, 0, CAsyncEventNotifier::ThreadProc, this, 0, &m_ThreadId); @@ -143,7 +162,7 @@ bool SAL_CALL CAsyncEventNotifier::start() // //------------------------------------------------ -void SAL_CALL CAsyncEventNotifier::stop() +void SAL_CALL CAsyncEventNotifier::shutdown() { OSL_PRECOND(GetCurrentThreadId() != m_ThreadId, "Method called in wrong thread context!"); @@ -153,7 +172,10 @@ void SAL_CALL CAsyncEventNotifier::stop() m_bRun = false; m_EventList.clear(); - m_NotifyEvent.set( ); + + // awake the the notifier thread + SetEvent(m_ResumeNotifying); + SetEvent(m_NotifyEvent); // releas the mutex here because the event // notifier thread may need it to finish @@ -177,6 +199,24 @@ void SAL_CALL CAsyncEventNotifier::stop() // //------------------------------------------------ +void CAsyncEventNotifier::suspend() +{ + ResetEvent(m_ResumeNotifying); +} + +//------------------------------------------------ +// +//------------------------------------------------ + +void CAsyncEventNotifier::resume() +{ + SetEvent(m_ResumeNotifying); +} + +//------------------------------------------------ +// +//------------------------------------------------ + void SAL_CALL CAsyncEventNotifier::notifyEvent(CEventNotification* EventNotification) { osl::MutexGuard aGuard(m_Mutex); @@ -186,7 +226,7 @@ void SAL_CALL CAsyncEventNotifier::notifyEvent(CEventNotification* EventNotifica if (m_bRun) { m_EventList.push_back(EventNotification); - m_NotifyEvent.set(); + SetEvent(m_NotifyEvent); } } @@ -208,7 +248,7 @@ void SAL_CALL CAsyncEventNotifier::resetNotifyEvent() { osl::MutexGuard aGuard(m_Mutex); if (0 == m_EventList.size()) - m_NotifyEvent.reset(); + ResetEvent(m_NotifyEvent); } //------------------------------------------------ @@ -239,7 +279,7 @@ void SAL_CALL CAsyncEventNotifier::run() { while (m_bRun) { - m_NotifyEvent.wait(); + WaitForMultipleObjects(2, m_hEvents, true, INFINITE); if (m_bRun) { diff --git a/fpicker/source/win32/filepicker/asynceventnotifier.hxx b/fpicker/source/win32/filepicker/asynceventnotifier.hxx index 84597c1bdc2c..26d6af00659f 100644 --- a/fpicker/source/win32/filepicker/asynceventnotifier.hxx +++ b/fpicker/source/win32/filepicker/asynceventnotifier.hxx @@ -2,9 +2,9 @@ * * $RCSfile: asynceventnotifier.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: tra $ $Date: 2002-03-28 08:57:33 $ + * last change: $Author: tra $ $Date: 2002-11-26 09:21:59 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -97,8 +97,17 @@ public: CAsyncEventNotifier(cppu::OBroadcastHelper& rBroadcastHelper); ~CAsyncEventNotifier(); - bool SAL_CALL start(); - void SAL_CALL stop(); + bool SAL_CALL startup(bool bCreateSuspended = true); + void SAL_CALL shutdown(); + + // notifications may be added the + // the event queue but will only + // be notified to the clients after + // resume was called + void suspend(); + + // resume notifying events + void resume(); // this class is responsible for the memory management of // the CEventNotification instance @@ -120,7 +129,9 @@ private: bool m_bRun; unsigned m_ThreadId; ::cppu::OBroadcastHelper& m_rBroadcastHelper; - osl::Condition m_NotifyEvent; + HANDLE m_hEvents[2]; + HANDLE& m_NotifyEvent; + HANDLE& m_ResumeNotifying; osl::Mutex m_Mutex; // prevent copy and assignment -- cgit