...which empirically shows that LateInitThread is useless

Change-Id: Ic2946eef616eae39576d162ca534831753bd3c89
This commit is contained in:
Stephan Bergmann
2014-06-05 22:16:59 +02:00
parent 416367380c
commit f7fac10510
7 changed files with 2 additions and 376 deletions
-2
View File
@@ -55,8 +55,6 @@ $(eval $(call gb_Library_add_exception_objects,filterconfig,\
filter/source/config/cache/filtercache \
filter/source/config/cache/filterfactory \
filter/source/config/cache/frameloaderfactory \
filter/source/config/cache/lateinitlistener \
filter/source/config/cache/lateinitthread \
filter/source/config/cache/querytokenizer \
filter/source/config/cache/registration \
filter/source/config/cache/typedetection \
+1 -15
View File
@@ -19,7 +19,6 @@
#include "filtercache.hxx"
#include "lateinitlistener.hxx"
#include "macros.hxx"
#include "constant.hxx"
#include "cacheupdatelistener.hxx"
@@ -156,18 +155,12 @@ void FilterCache::takeOver(const FilterCache& rClone)
void FilterCache::load(EFillState eRequired,
sal_Bool bByThread
)
void FilterCache::load(EFillState eRequired)
throw(css::uno::Exception)
{
// SAFE -> ----------------------------------
::osl::ResettableMutexGuard aLock(m_aLock);
SAL_WARN_IF(
bByThread && (eRequired & ~m_eFillState) == 0, "filter.config",
"useless LateInitThread");
// check if required fill state is already reached ...
// There is nothing to do then.
if ((m_eFillState & eRequired) == eRequired)
@@ -193,13 +186,6 @@ void FilterCache::load(EFillState eRequired,
// Support the old configuration support. Read it only one times during office runtime!
impl_readOldFormat();
// enable "loadOnDemand" feature ...
// Create uno listener, which waits for finishing the office startup
// and starts a thread, which calls loadAll() at this filter cache.
// Note: Its not a leak to create this listener with new here.
// It kills itself after working!
/* LateInitListener* pLateInit = */ new LateInitListener(comphelper::getProcessComponentContext());
}
+1 -20
View File
@@ -314,32 +314,13 @@ class FilterCache : public BaseLock
This method must be called from every user of this cache
every time it needs a filled cache. Normally we load
only standard information into this cache on startup.
After a few seconds we start a special thread, which
may fill this cache completely. But if someone outside
needs a filled cache before ... it can run into trouble,
if this "load-on-demand" thread does not finished its work before.
This method "load(xxx)" synchronize such load-on-demand requests.
Of course it would be possible to supress this special load thread
in general and start it manually inside this load() request.
The outside code decide then, if and when this cache will be filled
with all available information ...
@param bByThread
indicates using of this method by our global "load-on-demand-thread".
Its an implementation detail! We use it to check, if this "load()"
request was forced e.g. by one of our derived service container (which need
it to full fill its own operations) or if it was forced by our own
"load-on-demand-thread", which tries to optimize our startup performance
and start this load() only in case the office startup was already finished!
@throw An exception if the cache could not be filled really
or seems to be invalid afterwards. But there is no reaction
at all if this method does nothing inside, because the cache
is already full filled!
*/
virtual void load(EFillState eRequired ,
sal_Bool bByThread = sal_False)
virtual void load(EFillState eRequired)
throw(css::uno::Exception);
-126
View File
@@ -1,126 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "sal/config.h"
#include "rtl/ref.hxx"
#include "rtl/ustring.hxx"
#include "lateinitlistener.hxx"
#include "lateinitthread.hxx"
#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
namespace filter{
namespace config{
LateInitListener::LateInitListener(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
: BaseLock( )
{
// important to do so ...
// Otherwise the temp. reference to ourselves
// will kill us at releasing time!
osl_atomic_increment( &m_refCount );
m_xBroadcaster = css::uno::Reference< css::document::XEventBroadcaster >(
css::frame::theGlobalEventBroadcaster::get(rxContext),
css::uno::UNO_QUERY_THROW);
m_xBroadcaster->addEventListener(static_cast< css::document::XEventListener* >(this));
osl_atomic_decrement( &m_refCount );
}
LateInitListener::~LateInitListener()
{
}
void SAL_CALL LateInitListener::notifyEvent(const css::document::EventObject& aEvent)
throw(css::uno::RuntimeException, std::exception)
{
// wait for events which either
// a) indicate completed open of the first document in which case launch thread
// b) indicate close of application without any documents opened, in which case skip launching thread but drop references break cyclic dependencies in
// case of e.g. cancel from open/new database wizard or impress wizard
if ( aEvent.EventName == "OnNew" || aEvent.EventName == "OnLoad" || aEvent.EventName == "OnCloseApp" )
{
// this thread must be started one times only ...
// cancel listener connection before!
// SAFE ->
::osl::ResettableMutexGuard aLock(m_aLock);
if ( !m_xBroadcaster.is() )
// the beauty of multi-threading ... OnLoad can be notified synchronously or asynchronously. In particular,
// SFX-based documents notify it synchronously, database documents do it asynchronously.
// Now if multiple documents are opened "at the same time", it is well possible that we get two events from
// different threads, where upon the first event, we already remove ourself from m_xBroadcaster, and start
// the thread, nonetheless there's also a second notification "in the queue", which will arrive short
// thereafter.
// In such a case, simply ignore this second event.
return;
m_xBroadcaster->removeEventListener(static_cast< css::document::XEventListener* >(this));
m_xBroadcaster.clear();
aLock.clear();
// <- SAFE
if ( aEvent.EventName != "OnCloseApp" )
{
rtl::Reference< LateInitThread >(new LateInitThread())->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
}
}
}
void SAL_CALL LateInitListener::disposing(const css::lang::EventObject& /* aEvent */ )
throw(css::uno::RuntimeException, std::exception)
{
// ???
// Normaly it should never be called. Because we cancel our listener connection
// if we got the event about finished open of the first office document.
// But if this method was reached, it indicates an office, which was started
// (might as remote script container for an external API client) but not really used.
// SAFE ->
::osl::ResettableMutexGuard aLock(m_aLock);
if ( !m_xBroadcaster.is() )
return;
m_xBroadcaster->removeEventListener(static_cast< css::document::XEventListener* >(this));
m_xBroadcaster.clear();
aLock.clear();
// <- SAFE
}
} // namespace config
} // namespace filter
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-111
View File
@@ -1,111 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_FILTER_SOURCE_CONFIG_CACHE_LATEINITLISTENER_HXX
#define INCLUDED_FILTER_SOURCE_CONFIG_CACHE_LATEINITLISTENER_HXX
#include "cacheitem.hxx"
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XEventListener.hpp>
#include <com/sun/star/document/XEventListener.hpp>
#include <com/sun/star/document/XEventBroadcaster.hpp>
#include <cppuhelper/implbase1.hxx>
namespace com { namespace sun { namespace star { namespace uno {
class XComponentContext;
} } } }
namespace filter{
namespace config{
/** @short implements a listener, which will update the
global filter cache of an office, after zje office
startup was finished.
@descr To perform startup of an office, the filter cache starts
with a minimum set of properties only. After the first document
was loaded successfully a thread will be started to fill the
cache with all other proeprties, so it can work with the whole
filter configuration.
*/
class LateInitListener : public BaseLock // must be the first one to guarantee right initialized mutex member!
, public ::cppu::WeakImplHelper1< css::document::XEventListener >
{
// member
private:
/** @short reference to the global event broadcaster, which is usde to find
out, when the first office document was opened successfully. */
css::uno::Reference< css::document::XEventBroadcaster > m_xBroadcaster;
// native interface
public:
// ctor/dtor
/** @short initialize new instance of this class.
@descr It set a reference to the global filter cache singleton,
which should be updated here. Further it starts listening
on the global event broadcaster to get the information, when
loading of the first document was finished.
@param rxContext
reference to a component context, which can be used to create
own needed uno services.
*/
LateInitListener(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
/** @short standard dtor.
*/
virtual ~LateInitListener();
// uno interface
public:
// document.XEventListener
virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent)
throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// lang.XEventListener
virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
};
} // namespace config
} // namespace filter
#endif // INCLUDED_FILTER_SOURCE_CONFIG_CACHE_LATEINITLISTENER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-49
View File
@@ -1,49 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "sal/config.h"
#include "salhelper/singletonref.hxx"
#include "filtercache.hxx"
#include "lateinitthread.hxx"
namespace filter { namespace config {
LateInitThread::LateInitThread(): Thread("lateinitthread") {}
LateInitThread::~LateInitThread() {}
void LateInitThread::execute() {
// true => It indicates using of this method by this thread
// The filter cache use this information to show an assertion
// for "optimization failure" in case the first calli of loadAll()
// was not this thread ...
// Further please dont catch any exception here.
// May be they show the problem of a corrupted filter
// configuration, which is handled inside our event loop or desktop.main()!
salhelper::SingletonRef< FilterCache >()->load(
FilterCache::E_CONTAINS_ALL, true);
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-53
View File
@@ -1,53 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_FILTER_SOURCE_CONFIG_CACHE_LATEINITTHREAD_HXX
#define INCLUDED_FILTER_SOURCE_CONFIG_CACHE_LATEINITTHREAD_HXX
#include "sal/config.h"
#include "salhelper/thread.hxx"
namespace filter{ namespace config {
/** @short implements a thread, which will update the
global filter cache of an office, after its
startup was finished.
@descr Its started by a LateInitListener instance ...
@see LateInitListener
@attention The filter cache will be blocked during this thrad runs!
*/
class LateInitThread: public salhelper::Thread {
public:
LateInitThread();
private:
virtual ~LateInitThread();
virtual void execute() SAL_OVERRIDE;
};
} }
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */