diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-05-07 12:44:36 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-05-10 08:01:25 +0200 |
commit | 8809b57da900c0fa8e7aa9d05021fe9a00114ecd (patch) | |
tree | b7647554589c635ada0e6bf9923937aa4713e2d0 /cppuhelper/source | |
parent | c84b37c0bbab3b386b22b87be52f965839b44a49 (diff) |
use WeakComponentImplHelper2 in ServiceManager
Change-Id: I0f141398effbd2673c02f9d1f4378fd4e67af655
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151580
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cppuhelper/source')
-rw-r--r-- | cppuhelper/source/servicemanager.cxx | 41 | ||||
-rw-r--r-- | cppuhelper/source/servicemanager.hxx | 18 |
2 files changed, 28 insertions, 31 deletions
diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx index 86d89e445dd4..7eccd274e7f4 100644 --- a/cppuhelper/source/servicemanager.cxx +++ b/cppuhelper/source/servicemanager.cxx @@ -795,7 +795,7 @@ void cppuhelper::ServiceManager::loadImplementation( { assert(implementation); { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); if (implementation->status == Data::Implementation::STATUS_LOADED) { return; } @@ -871,8 +871,8 @@ void cppuhelper::ServiceManager::loadImplementation( //TODO: There is a race here, as the relevant service factory can be removed // while the mutex is unlocked and loading can thus fail, as the entity from // which to load can disappear once the service factory is removed. - osl::MutexGuard g(rBHelper.rMutex); - if (!(isDisposed() + std::unique_lock g(m_aMutex); + if (!(m_bDisposed || implementation->status == Data::Implementation::STATUS_LOADED)) { implementation->status = Data::Implementation::STATUS_LOADED; @@ -882,12 +882,11 @@ void cppuhelper::ServiceManager::loadImplementation( } } -void cppuhelper::ServiceManager::disposing() { +void cppuhelper::ServiceManager::disposing(std::unique_lock<std::mutex>& rGuard) { std::vector< css::uno::Reference<css::lang::XComponent> > sngls; std::vector< css::uno::Reference< css::lang::XComponent > > comps; Data clear; { - osl::MutexGuard g(rBHelper.rMutex); for (const auto& rEntry : data_.namedImplementations) { assert(rEntry.second); @@ -916,6 +915,7 @@ void cppuhelper::ServiceManager::disposing() { data_.services.swap(clear.services); data_.singletons.swap(clear.singletons); } + rGuard.unlock(); for (const auto& rxSngl : sngls) { try { @@ -928,6 +928,7 @@ void cppuhelper::ServiceManager::disposing() { { removeEventListenerFromComponent(rxComp); } + rGuard.lock(); } void cppuhelper::ServiceManager::initialize( @@ -983,8 +984,8 @@ cppuhelper::ServiceManager::createInstanceWithArguments( css::uno::Sequence< OUString > cppuhelper::ServiceManager::getAvailableServiceNames() { - osl::MutexGuard g(rBHelper.rMutex); - if (isDisposed()) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { return css::uno::Sequence< OUString >(); } if (data_.services.size() > o3tl::make_unsigned(SAL_MAX_INT32)) { @@ -1025,7 +1026,7 @@ css::uno::Type cppuhelper::ServiceManager::getElementType() sal_Bool cppuhelper::ServiceManager::hasElements() { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); return !(data_.namedImplementations.empty() && data_.dynamicImplementations.empty()); @@ -1138,7 +1139,7 @@ cppuhelper::ServiceManager::createContentEnumeration( { std::vector< std::shared_ptr< Data::Implementation > > impls; { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); Data::ImplementationMap::const_iterator i( data_.services.find(aServiceName)); if (i != data_.services.end()) { @@ -1151,8 +1152,8 @@ cppuhelper::ServiceManager::createContentEnumeration( Data::Implementation * impl = rxImpl.get(); assert(impl != nullptr); { - osl::MutexGuard g(rBHelper.rMutex); - if (isDisposed()) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { factories.clear(); break; } @@ -1572,8 +1573,8 @@ void cppuhelper::ServiceManager::insertLegacyFactory( bool cppuhelper::ServiceManager::insertExtraData(Data const & extra) { { - osl::MutexGuard g(rBHelper.rMutex); - if (isDisposed()) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { return false; } auto i = std::find_if(extra.namedImplementations.begin(), extra.namedImplementations.end(), @@ -1651,7 +1652,7 @@ void cppuhelper::ServiceManager::removeRdbFiles( // it is called with a uris vector of size one): std::vector< std::shared_ptr< Data::Implementation > > clear; { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); for (const auto& rUri : uris) { for (Data::NamedImplementations::iterator j( @@ -1686,11 +1687,11 @@ bool cppuhelper::ServiceManager::removeLegacyFactory( std::shared_ptr< Data::Implementation > clear; css::uno::Reference< css::lang::XComponent > comp; { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); Data::DynamicImplementations::iterator i( data_.dynamicImplementations.find(factoryInfo)); if (i == data_.dynamicImplementations.end()) { - return isDisposed(); + return m_bDisposed; } assert(i->second); clear = i->second; @@ -1718,8 +1719,8 @@ void cppuhelper::ServiceManager::removeImplementation(const OUString & name) { // but the assumption is that it is rarely called: std::shared_ptr< Data::Implementation > clear; { - osl::MutexGuard g(rBHelper.rMutex); - if (isDisposed()) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { return; } Data::NamedImplementations::iterator i( @@ -1752,7 +1753,7 @@ cppuhelper::ServiceManager::findServiceImplementation( std::shared_ptr< Data::Implementation > impl; bool loaded; { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); Data::ImplementationMap::const_iterator i( data_.services.find(specifier)); if (i == data_.services.end()) { @@ -1814,7 +1815,7 @@ void cppuhelper::ServiceManager::preloadImplementations() { abort(); #else OUString aUri; - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); css::uno::Environment aSourceEnv(css::uno::Environment::getCurrent()); std::cerr << "preload:"; diff --git a/cppuhelper/source/servicemanager.hxx b/cppuhelper/source/servicemanager.hxx index cdf23b277040..af80be25a183 100644 --- a/cppuhelper/source/servicemanager.hxx +++ b/cppuhelper/source/servicemanager.hxx @@ -12,10 +12,11 @@ #include <sal/config.h> #include <cassert> -#include <unordered_map> +#include <functional> #include <memory> #include <mutex> #include <string_view> +#include <unordered_map> #include <utility> #include <vector> @@ -29,8 +30,7 @@ #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/Reference.hxx> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> +#include <compbase2.hxx> #include <rtl/ustring.hxx> namespace com::sun::star::lang { @@ -53,7 +53,7 @@ typedef css::uno::XInterface * ImplementationConstructorFn( typedef std::function<css::uno::XInterface * (css::uno::XComponentContext *, css::uno::Sequence<css::uno::Any> const&)> WrapperConstructorFn; -typedef cppu::WeakComponentImplHelper< +typedef WeakComponentImplHelper2< css::lang::XServiceInfo, css::lang::XMultiServiceFactory, css::lang::XMultiComponentFactory, css::container::XSet, css::container::XContentEnumerationAccess, css::beans::XPropertySet, @@ -61,8 +61,7 @@ typedef cppu::WeakComponentImplHelper< css::lang::XInitialization> ServiceManagerBase; -class ServiceManager: - private cppu::BaseMutex, public ServiceManagerBase +class ServiceManager : public ServiceManagerBase { public: struct Data { @@ -184,7 +183,7 @@ public: ImplementationMap singletons; }; - ServiceManager(): ServiceManagerBase(m_aMutex) {} + ServiceManager() {} ServiceManager(const ServiceManager&) = delete; const ServiceManager& operator=(const ServiceManager&) = delete; @@ -219,7 +218,7 @@ public: private: virtual ~ServiceManager() override; - virtual void SAL_CALL disposing() override; + virtual void disposing(std::unique_lock<std::mutex>&) override; virtual OUString SAL_CALL getImplementationName() override; @@ -308,9 +307,6 @@ private: css::uno::Sequence<css::uno::Any> const & aArguments) override; - // needs to be called with rBHelper.rMutex locked: - bool isDisposed() const { return rBHelper.bDisposed || rBHelper.bInDispose; } - void removeEventListenerFromComponent( css::uno::Reference< css::lang::XComponent > const & component); |