Tag: cws_src680_utf2 User: kso Date: 05/02/21 07:32:25 Modified: /dba/dbaccess/source/ui/browser/ brwctrlr.cxx, unodatbr.cxx /dba/dbaccess/source/ui/inc/ brwctrlr.hxx
Log: #109709# - Removed unused LoadFormThread and related code . File Changes: Directory: /dba/dbaccess/source/ui/browser/ =========================================== File [changed]: brwctrlr.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/browser/brwctrlr.cxx?r1=1.85&r2=1.85.4.1 Delta lines: +40 -308 ---------------------- --- brwctrlr.cxx 5 Jan 2005 12:33:18 -0000 1.85 +++ brwctrlr.cxx 21 Feb 2005 15:32:21 -0000 1.85.4.1 @@ -2,9 +2,9 @@ * * $RCSfile: brwctrlr.cxx,v $ * - * $Revision: 1.85 $ + * $Revision: 1.85.4.1 $ * - * last change: $Author: obo $ $Date: 2005/01/05 12:33:18 $ + * last change: $Author: kso $ $Date: 2005/02/21 15:32:21 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -532,10 +532,7 @@ //------------------------------------------------------------------------------ SbaXDataBrowserController::SbaXDataBrowserController(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM) :OGenericUnoController(_rM) - ,m_pLoadThread(NULL) - ,m_bClosingKillOpen( sal_False ) ,m_bLoadCanceled( sal_False ) - ,m_nPendingLoadFinished(0) ,m_sLoadStopperCaption(ModuleRes(RID_STR_LOADING_DATASOURCE)) ,m_nFormActionNestingLevel(0) ,m_bErrorOccured( sal_False ) @@ -1129,47 +1126,6 @@ { // m_bSuspending = sal_True; // - // have a pending open operation ? - if (PendingLoad()) - { - ::vos::OGuard aGuard(Application::GetSolarMutex()); - if (m_nPendingLoadFinished != 0) - { // clean up directly. Otherwise there may be a pending asynchronous call - // to OnOpenFinishedMainThread, which won't be executed before we leave - // this method. Sounds like a classic infinite loop. - Application::RemoveUserEvent(m_nPendingLoadFinished); - LINK(this, SbaXDataBrowserController, OnOpenFinishedMainThread).Call(NULL); - } - else - { // set m_bClosingKillOpen to ensure that the our termination handler reacts according - // it's context - m_bClosingKillOpen = sal_True; - - // normally we would now just wait for termination of the load thread, but there is a small problem : - // In the current thread the global solar mutex is locked (that's for sure). If the loading of the - // form tries to acquire (blocking) the solar mutex, too, and we loop waiting for the other thread - // we have a classic deadlock. And bet your ass that ANYBODY in the foreign thread tries to lock - // the solar mutex. Almost all the UNO-capsules around normal C++ classes use the solar mutex for - // "thread safety" (which doesn't deserve that name anymore ;), e.g. the ::com::sun::star::util::XNumberFormatter-implementation - // does. - // So we have to do a fake : we tell the loading thread that we aren't interested in the results anymore - // and the thread deletes itself (and the data source) as soon as it is done. As it holds the last - // references to the form (and thus, indirectly, to the grid) they will be cleared as soon as the thread dies. - // So all is fine. Except the small flaw that the form is still loading in the background while the - // window that should display it is already dead. - // If we could release the solar mutex in this thread and block it 'til the loader is finished we could - // solve it in a less dirty way, but uinfortunatelly we don't know how often this thread acquired the mutex. - // With high effort we could reach this with releasing the mutex until a third thread - which has to be - // created - can acquire it.Then we block, the third thread releases the mutex (and dies) and the loader - // thread would be able to finish. But that sounds difficult and fault-prone, so I think it's not worth it ... - ((LoadFormThread*)m_pLoadThread)->SetTerminationHdl(Link()); - // and of course we tell the thread to stop .... - ((LoadFormThread*)m_pLoadThread)->StopIt(); - } - - } - DBG_ASSERT(m_nPendingLoadFinished == 0, "SbaXDataBrowserController::suspend : there shouldn't be a pending load !"); - m_aAsyncGetCellFocus.CancelCall(); m_aAsyncInvalidateAll.CancelCall(); @@ -1201,17 +1157,6 @@ // the base class OGenericUnoController::disposing(); - if (!PendingLoad()) - { - // don't do the removeXxxListener calls if there is a pending load, this may lead to a deadlock : - // as in this thread the SolarMutex is locked (that's for sure) and removeXxxListener locks - // the form's mutex. But in the loading thread both mutexes are acquired in reverse order. - // That's no problem that we don't remove ourself here, as the load thread is responsible for the form - // at the moment. So if the loading is finished, the form will be disposed (by the load thread), and - // we get the "disposing" event where we can do the removeXxxListener calls. - // The alternative for this handling would be that the form has two mutexes : one for handling it's - // listeners and properties and so on, on for it's pure cursor actions - // the data source Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY); if (xFormSet.is()) @@ -1236,7 +1181,6 @@ Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY); if (xFormParameter.is()) xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this); - } removeModelListeners(getControlModel()); @@ -1259,10 +1203,6 @@ m_aInvalidateClipboard.Stop(); // dispose the data source - // if there is a pending load we decided to give the responsibility for the data source to the open thread - // (see ::suspend) - if (!PendingLoad()) - { try { ::comphelper::disposeComponent(m_xRowSet); @@ -1275,7 +1215,7 @@ { OSL_ENSURE(0,"Exception thrown by dispose"); } - } + try { ::comphelper::disposeComponent(m_xParser); @@ -1455,9 +1395,6 @@ // no chance without valid models if (isValid() && !isValidCursor()) return aReturn; - // no chance while loading the form - if (PendingLoad()) - return aReturn; switch (nId) { @@ -2401,45 +2338,6 @@ } //------------------------------------------------------------------------------ -IMPL_LINK(SbaXDataBrowserController, OnOpenFinishedMainThread, void*, EMPTYARG) -{ - ::vos::OGuard aGuard(Application::GetSolarMutex()); - if (!m_nPendingLoadFinished) - // it's possible that the direct call of this link from within suspend caused this method to be executed - // in another thread while we were waiting for the mutex in this thread - return 0; - m_nPendingLoadFinished = 0; - - if ( static_cast< LoadFormThread* >( m_pLoadThread )->WasCanceled() ) - setLoadingCancelled(); - - delete m_pLoadThread; - m_pLoadThread = NULL; - - LoadFinished(sal_False); - - return 0L; -} - -//------------------------------------------------------------------------------ -IMPL_LINK(SbaXDataBrowserController, OnOpenFinished, void*, EMPTYARG) -{ - ::osl::MutexGuard aCheckGuard(m_aAsyncLoadSafety); - - if (m_bClosingKillOpen) - { - delete m_pLoadThread; - m_pLoadThread = NULL; - } - else - // all cleaning has to run in the main thread, not here (this is called synchronously from the LoadThread) - // so we use an user event - m_nPendingLoadFinished = Application::PostUserEvent(LINK(this, SbaXDataBrowserController, OnOpenFinishedMainThread)); - - return 0L; -} - -//------------------------------------------------------------------------------ IMPL_LINK(SbaXDataBrowserController, OnAsyncGetCellFocus, void*, EMPTYARG) { SbaGridControl* pVclGrid = getBrowserView() ? getBrowserView()->getVclControl() : NULL; @@ -2514,7 +2412,6 @@ void SbaXDataBrowserController::loaded(const EventObject& aEvent) throw( RuntimeException ) { // not interested in - // we're loading within an separate thread and have a handling for it's "finished event" } //------------------------------------------------------------------------------ @@ -2750,171 +2647,6 @@ return true; } -//================================================================== -// LoadFormThread - a thread for asynchronously loading a form -//================================================================== -//------------------------------------------------------------------------------ -void LoadFormThread::run() -{ - // On instantiation of a SfxCancellable the application is notified and 'switches on' the red stop button. - // Unfortunally this is conditioned with the acquirement of the solar mutex, and the application tries - // only once and ignores the notification if it fails. - // To prevent that we get the solar mutex and _block_ 'til we got it. - // As we are in the 'top level execution' of this thread (with a rather small stack and no other mutexes locked) - // we shouldn't experience problems with deadlocks ... - ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex()); - ThreadStopper* pStopper = new ThreadStopper(this, m_sStopperCaption); - aSolarGuard.clear(); - - // we're not canceled yet - ::osl::ClearableMutexGuard aResetGuard(m_aAccessSafety); - m_bCanceled = sal_False; - aResetGuard.clear(); - - LoadFormHelper* pHelper = new LoadFormHelper(m_xRowSet); - pHelper->acquire(); - - // start it - bool bErrorOccured = false; - Reference< XLoadable > xLoadable(m_xRowSet, UNO_QUERY); - try - { - Reference< XRowSet > xMove(m_xRowSet, UNO_QUERY); - DBG_ASSERT(xLoadable.is() && xMove.is(), "LoadFormThread::run : invalid cursor !"); - xLoadable->load(); - // go to the first record if the load was successfull. - Reference< XColumnsSupplier > xColumnsSupplier(m_xRowSet, UNO_QUERY); - Reference< ::com::sun::star::container::XNameAccess > xCols = xColumnsSupplier.is() ? xColumnsSupplier->getColumns() : Reference< ::com::sun::star::container::XNameAccess > (); - if (xCols.is() && xCols->hasElements()) - xMove->first(); - else - bErrorOccured = true; - } - catch(Exception&) - { - bErrorOccured = true; - } - - // check if we were canceled - ::osl::ClearableMutexGuard aTestGuard(m_aAccessSafety); - bool bReallyCanceled = m_bCanceled ? true : false;; - aTestGuard.clear(); - - bReallyCanceled |= bErrorOccured; - - // the load on the form is "slightly asyncronous" (which isn't covered by it's specification, anyway), so wait - // some time .... - // (though me thinks that the load of the new api is synchronous, so we won't need this LoadFormHelper anymore ...) - if (!bReallyCanceled) - pHelper->WaitUntilReallyLoaded(true); - - pHelper->cancel(); - pHelper->release(); - - // yes, we were, but eventually the cancel request didn't reach the data source in time - if (bReallyCanceled && xLoadable.is() && xLoadable->isLoaded()) - xLoadable->unload(); - - pStopper->OwnerTerminated(); - // this will cause the stopper to delete itself (in the main thread) so we don't have to take care of the - // solar mutex -} - -//------------------------------------------------------------------------------ -void LoadFormThread::onTerminated() -{ - ::osl::ClearableMutexGuard aGuard(m_aAccessSafety); - if (m_aTerminationHandler.IsSet()) - { - // within the call of our termination handler we may be deleted, so do anything which is a member - // access before the call ... - // FS - #69801# - 02.12.99 - Link aHandler(m_aTerminationHandler); - aGuard.clear(); - aHandler.Call(this); - } - else - { - // we are fully responsible for the data source and for ourself, so dispose the former ... - try - { - ::comphelper::disposeComponent(m_xRowSet); - - m_xRowSet = NULL; - } - catch(Exception&) - { - OSL_ENSURE(0,"Exception thrown by dispose"); - } - // ... and delete the latter - aGuard.clear(); // like above - releasing the mutex is a member access ... - delete this; - } -} - -//------------------------------------------------------------------------------ -void LoadFormThread::StopIt() -{ - ::osl::ClearableMutexGuard aResetGuard(m_aAccessSafety); - m_bCanceled = sal_True; - aResetGuard.clear(); - - Reference< XColumnsSupplier > xColumnsSupplier(m_xRowSet, UNO_QUERY); - if (!xColumnsSupplier.is()) - { - DBG_ERROR("LoadFormThread::StopIt : invalid data source !"); - return; - } - Reference< ::com::sun::star::container::XNameAccess > xCols(xColumnsSupplier->getColumns(), UNO_QUERY); - if (!xCols.is() || !xCols->hasElements()) - // the cursor isn't alive, don't need to cancel - return; - - Reference< ::com::sun::star::util::XCancellable > xCancel(m_xRowSet, UNO_QUERY); - if (xCancel.is()) - { - try { xCancel->cancel(); } catch(SQLException&) {} - // with this the cursor returns from it's load call, this terminates our run, this get's our termination handler to - // be called - // (the try-catch is just in case the cancel wasn't neccessary anymore) - } -} - -//------------------------------------------------------------------------------ -LoadFormThread::ThreadStopper::ThreadStopper(LoadFormThread* pOwner, const String& rTitle) - :SfxCancellable(SFX_APP()->GetCancelManager(), rTitle) - ,m_pOwner(pOwner) -{ -} - -//------------------------------------------------------------------------------ -void LoadFormThread::ThreadStopper::Cancel() -{ - if (!m_pOwner) - return; - - ::osl::MutexGuard aGuard(m_pOwner->m_aAccessSafety); - if (IsCancelled()) - // we already did pass this to our owner - return; - - SfxCancellable::Cancel(); - m_pOwner->StopIt(); -} - -//------------------------------------------------------------------------------ -void LoadFormThread::ThreadStopper::OwnerTerminated() -{ - m_pOwner = NULL; - Application::PostUserEvent(LINK(this, LoadFormThread::ThreadStopper, OnDeleteInMainThread), this); -} - -//------------------------------------------------------------------------------ -IMPL_LINK(LoadFormThread::ThreadStopper, OnDeleteInMainThread, LoadFormThread::ThreadStopper*, pThis) -{ - delete pThis; - return 0L; -} // ----------------------------------------------------------------------------- sal_uInt16 SbaXDataBrowserController::getCurrentColumnPosition() { File [changed]: unodatbr.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/browser/unodatbr.cxx?r1=1.165&r2=1.165.22.1 Delta lines: +3 -7 ------------------- --- unodatbr.cxx 21 Jan 2005 17:09:34 -0000 1.165 +++ unodatbr.cxx 21 Feb 2005 15:32:22 -0000 1.165.22.1 @@ -2,9 +2,9 @@ * * $RCSfile: unodatbr.cxx,v $ * - * $Revision: 1.165 $ + * $Revision: 1.165.22.1 $ * - * last change: $Author: kz $ $Date: 2005/01/21 17:09:34 $ + * last change: $Author: kso $ $Date: 2005/02/21 15:32:22 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1715,10 +1715,6 @@ // no chance without valid models if (isValid() && !isValidCursor() && nId != ID_BROWSER_CLOSE) - return aReturn; - - // no chance while loading the form - if (PendingLoad()) return aReturn; switch (nId) Directory: /dba/dbaccess/source/ui/inc/ ======================================= File [changed]: brwctrlr.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/inc/brwctrlr.hxx?r1=1.30&r2=1.30.4.1 Delta lines: +3 -77 -------------------- --- brwctrlr.hxx 5 Jan 2005 12:36:10 -0000 1.30 +++ brwctrlr.hxx 21 Feb 2005 15:32:22 -0000 1.30.4.1 @@ -2,9 +2,9 @@ * * $RCSfile: brwctrlr.hxx,v $ * - * $Revision: 1.30 $ + * $Revision: 1.30.4.1 $ * - * last change: $Author: obo $ $Date: 2005/01/05 12:36:10 $ + * last change: $Author: kso $ $Date: 2005/02/21 15:32:22 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -116,9 +116,6 @@ #ifndef _OSL_MUTEX_HXX_ #include <osl/mutex.hxx> #endif -#ifndef _VOS_THREAD_HXX_ -#include <vos/thread.hxx> -#endif #ifndef _SFXCANCEL_HXX #include <svtools/cancel.hxx> #endif @@ -174,8 +171,6 @@ TransferableClipboardListener* m_pClipbordNotifier; // notifier for changes in the clipboard - ::osl::Mutex m_aAsyncLoadSafety; // for multi-thread access to our members - OAsyncronousLink m_aAsyncGetCellFocus; String m_sLoadStopperCaption; @@ -185,14 +180,12 @@ String m_sStateUndoRecord; // members for asynchronous load operations - ::vos::OThread* m_pLoadThread; // the thread wherein the form is loaded FormControllerImpl* m_pFormControllerImpl; // implementing the XFormController sal_uInt32 m_nPendingLoadFinished; // the event used to tell ourself that the load is finished sal_uInt16 m_nFormActionNestingLevel; // see enter-/leaveFormAction sal_Bool m_bLoadCanceled : 1; // the load was canceled somehow - sal_Bool m_bClosingKillOpen : 1; // are we killing the load thread because we are to be suspended ? sal_Bool m_bErrorOccured : 1; // see enter-/leaveFormAction protected: @@ -377,9 +370,6 @@ // a PropertySet corresponding to the cursor field a column is bound to // if nViewPos is (sal_uInt16)-1 (the default) then the field for the current column will be retrieved - sal_Bool PendingLoad() const { return m_pLoadThread != NULL; } - // is there an asyncronous load operation in progress ? - void enterFormAction(); void leaveFormAction(); bool errorOccured() const { return m_bErrorOccured; } @@ -417,71 +407,7 @@ DECL_LINK(OnFoundData, FmFoundRecordInformation*); DECL_LINK(OnCanceledNotFound, FmFoundRecordInformation*); - // callbacks for the completed loading process - DECL_LINK(OnOpenFinished, void*); - DECL_LINK(OnOpenFinishedMainThread, void*); - // OnOpenFinsihed is called in a foreign thread (the one which does the loading) so it simply posts the - // OnOpenFinishedMainThread-link (which will be called in the main thread, then) as user event. - // (the alternative would be to lock the SolarMutex in OnOpenFinished to avoid problems with the needed updates, - // but playing with this mutex seems very hazardous to me ....) DECL_LINK(OnAsyncGetCellFocus, void*); - }; - - //================================================================== - // LoadFormThread - a thread for asynchronously loading a form - //================================================================== - class LoadFormThread : public ::vos::OThread - { - ::osl::Mutex m_aAccessSafety; // for securing the multi-thread access - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // the data source to be loaded - - Link m_aTerminationHandler; // the handler to be called upon termination - sal_Bool m_bCanceled; // StopIt has been called ? - String m_sStopperCaption; // the caption for the ThreadStopper - - // a ThreadStopper will be instantiated so that the open can be canceled via the UI - class ThreadStopper : protected SfxCancellable - { - LoadFormThread* m_pOwner; - - public: - ThreadStopper(LoadFormThread* pOwner, const String& rTitle); - virtual ~ThreadStopper() { } - - virtual void Cancel(); - - virtual void OwnerTerminated(); - // Normally the Owner (a LoadFormThread) would delete the stopper when terminated. - // Unfortunally the application doesn't remove the 'red light' when a SfxCancellable is deleted - // if it (the app) can't acquire the solar mutex. The deletion is IGNORED then. So we have to make - // sure that a) the stopper is deleted from inside the main thread (where the solar mutex is locked) - // and b) that in the time between the termination of the thread and the deletion of the stopper - // the latter doesn't access the former. - // The OwnerTerminated cares for both aspects. - // SO DON'T DELETE THE STOPPER EXPLICITLY ! - - protected: - // HACK HACK HACK HACK HACK : this should be private, but MSVC doesn't accept the LINK-macro then .... - DECL_LINK(OnDeleteInMainThread, ThreadStopper*); - }; - friend class LoadFormThread::ThreadStopper; - - public: - LoadFormThread(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > & _xRowSet, const String& _rStopperCaption) : m_xRowSet(_xRowSet), m_sStopperCaption(_rStopperCaption) { } - - virtual void SAL_CALL run(); - virtual void SAL_CALL onTerminated(); - - void SetTerminationHdl(const Link& aTermHdl) { m_aTerminationHandler = aTermHdl; } - // the handler will be called synchronously (the parameter is a pointer to the thread) - // if no termination handler is set, the thread disposes the data source and deletes - // itself upon termination - - // cancels the process. to be called from another thread (of course ;) - void StopIt(); - - // ask if the load canceled - sal_Bool WasCanceled() const { return m_bCanceled; } }; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
