Files
core/configmgr/source/components.hxx
Stephan Bergmann a0ffaeeff9 Shrink critical section into writeModFile
...from the calling configmgr::Components::WriteThread::execute.  This is
relevant at least for an upcoming Emscripten Qt6 JSPI/non-PROXY_TO_PTHREAD mode,
where part of the LO event handling (which would normally take place on the main
thread) will be offloaded to an additional thread.  There, opening e.g. a fresh
Writer document shortly after starting LO could have lead to a deadlock:

The configmgrWriter thread had the configmgr::Components mutex locked and tried
to do a mkdir, which it needs to proxy to the main thread on Emscripten,

> $emscripten_futex_wait (soffice.wasm:0x83dbf64)
> $__timedwait_cp (soffice.wasm:0x83e7f34)
> $__pthread_cond_timedwait (soffice.wasm:0x83e8168)
> $pthread_cond_wait (soffice.wasm:0x83e85a2)
> $emscripten_proxy_sync_with_ctx (soffice.wasm:0x83e6709)
> $emscripten_proxy_sync (soffice.wasm:0x83e6a08)
> $_emscripten_run_on_main_thread_js (soffice.wasm:0x83e6d77)
> ret.<computed> (soffice.js:8709)
> (anonymous) (soffice.js:1285)
> proxyToMainThread (soffice.js:1617)
> ___syscall_mkdirat (soffice.js:6613)
> $mkdir (soffice.wasm:0x83e3e0a)
> $osl::mkdir(rtl::OString const&, unsigned int) (soffice.wasm:0xbce7b3)
> $create_dir_with_callback(char*, void (*)(void*, _rtl_uString*), void*) (soffice.wasm:0xbdc4d6)
> $create_dir_recursively_(char*, void (*)(void*, _rtl_uString*), void*) (soffice.wasm:0xbdc422)
> $osl_createDirectoryPath (soffice.wasm:0xbdc35f)
> $configmgr::writeModFile(configmgr::Components&, rtl::OUString const&, configmgr::Data const&) (soffice.wasm:0x4218d80)
> $configmgr::Components::WriteThread::execute() (soffice.wasm:0x41f561d)
> $non-virtual thunk to salhelper::Thread::run() (soffice.wasm:0xd369fd)
> $threadFunc (soffice.wasm:0xd36890)
> $osl_thread_start_Impl(void*) (soffice.wasm:0xbca617)

...while the main thread was serving a proxied call from the additional "event
handling offload" thread, during which it accesses configmgr code and tried to
lock the configmgr::Components mutex,

> $a_cas_p (soffice.wasm:0x83dc0d9)
> $futex_wait_main_browser_thread (soffice.wasm:0x83dbfed)
> $emscripten_futex_wait (soffice.wasm:0x83dbf23)
> $__timedwait_cp (soffice.wasm:0x83e7f34)
> $__timedwait (soffice.wasm:0x83e7fd2)
> $__pthread_mutex_timedlock (soffice.wasm:0x83e9323)
> $__pthread_mutex_lock (soffice.wasm:0x83e9208)
> $osl_acquireMutex (soffice.wasm:0xbbc750)
> $configmgr::Access::thisIs(int) (soffice.wasm:0x41dc351)
> $configmgr::Access::getByName(rtl::OUString const&) (soffice.wasm:0x41e13b3)
> $non-virtual thunk to configmgr::Access::getByName(rtl::OUString const&) (soffice.wasm:0x41e159a)
> $comphelper::detail::ConfigurationWrapper::getPropertyValue(std::__2::basic_string_view<char16_t, std::__2::char_traits<char16_t>>) const (soffice.wasm:0xc2f8fe)
> $comphelper::ConfigurationProperty<officecfg::Office::Common::Misc::ViewerAppMode, bool>::get(com::sun::uno::Reference<com::sun::uno::XComponentContext> const&) (soffice.wasm:0xdfbc05)
> $SfxDispatcher::FindServer_(unsigned short, SfxSlotServer&) (soffice.wasm:0xdfb6d4)
> $SfxDispatcher::GetShellAndSlot_Impl(unsigned short, SfxShell**, SfxSlot const**, bool, bool) (soffice.wasm:0xdfb398)
> $SfxDispatcher::QueryState(unsigned short, com::sun::uno::Any&) (soffice.wasm:0xe01fe3)
> $SfxDispatchController_Impl::addStatusListener(com::sun::uno::Reference<com::sun::frame::XStatusListener> const&, com::sun::util::URL const&) (soffice.wasm:0xe1d5bd)
> $SfxOfficeDispatch::addStatusListener(com::sun::uno::Reference<com::sun::frame::XStatusListener> const&, com::sun::util::URL const&) (soffice.wasm:0xe1d4ce)
> $non-virtual thunk to SfxOfficeDispatch::addStatusListener(com::sun::uno::Reference<com::sun::frame::XStatusListener> const&, com::sun::util::URL const&) (soffice.wasm:0xe1daa6)
> $svt::PopupMenuControllerBase::updateCommand(rtl::OUString const&) (soffice.wasm:0x20cd630)
> $svt::PopupMenuControllerBase::updatePopupMenu() (soffice.wasm:0x20cd460)
> $framework::HeaderMenuController::updatePopupMenu() (soffice.wasm:0x29a0323)
> $svt::PopupMenuControllerBase::setPopupMenu(com::sun::uno::Reference<com::sun::awt::XPopupMenu> const&) (soffice.wasm:0x20cf1bb)
> $non-virtual thunk to svt::PopupMenuControllerBase::setPopupMenu(com::sun::uno::Reference<com::sun::awt::XPopupMenu> const&) (soffice.wasm:0x20cf1e0)
> $framework::MenuBarManager::CreatePopupMenuController(framework::MenuBarManager::MenuItemHandler*, com::sun::uno::Reference<com::sun::frame::XDispatchProvider> const&, rtl::OUString const&) (soffice.wasm:0x217c209)
> $framework::MenuBarManager::Activate(Menu*) (soffice.wasm:0x218130b)
> $framework::MenuBarManager::Activate(Menu*) (soffice.wasm:0x2180b17)
> $framework::MenuBarManager::LinkStubActivate(void*, Menu*) (soffice.wasm:0x2180126)
> $Menu::Activate() (soffice.wasm:0x14d68e0)
> $Menu::HandleMenuActivateEvent(Menu*) const (soffice.wasm:0x14df42c)
> $QtMenu::DoFullMenuUpdate(Menu*) (soffice.wasm:0x6617932)
> $QtMenu::SetFrame(SalFrame const*) (soffice.wasm:0x661738a)
> $std::__2::__function::__func<QtMenu::SetFrame(SalFrame const*)::$_0, std::__2::allocator<QtMenu::SetFrame(SalFrame const*)::$_0>, void ()>::operator()() (soffice.wasm:0x661c275)
> $QtInstance::EmscriptenProxyToMainThread(std::__2::function<void ()>)::$_0::__invoke(void*) (soffice.wasm:0x65b24e4)

Change-Id: Iee58b86a96147273b7ae288524513e0d174287a8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181353
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2025-02-10 17:38:57 +01:00

169 lines
5.0 KiB
C++

/* -*- 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 .
*/
#pragma once
#include <sal/config.h>
#include <set>
#include <string_view>
#include <com/sun/star/beans/Optional.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <rtl/ref.hxx>
#include <o3tl/sorted_vector.hxx>
#include "additions.hxx"
#include "data.hxx"
#include "modifications.hxx"
namespace com::sun::star {
namespace beans { class XPropertySet; }
namespace uno {
class Any;
class XComponentContext;
}
}
namespace configmgr {
class Broadcaster;
class Node;
class Partial;
class RootAccess;
class Components {
public:
static Components & getSingleton(
css::uno::Reference< css::uno::XComponentContext > const & context);
static bool allLocales(std::u16string_view locale);
rtl::Reference< Node > resolvePathRepresentation(
OUString const & pathRepresentation,
OUString * canonicRepresentation, std::vector<OUString> * path, int * finalizedLayer)
const;
rtl::Reference< Node > getTemplate( OUString const & fullName) const;
void addRootAccess(rtl::Reference< RootAccess > const & access);
void removeRootAccess(RootAccess * access);
void initGlobalBroadcaster(
Modifications const & modifications,
rtl::Reference< RootAccess > const & exclude,
Broadcaster * broadcaster);
void addModification(std::vector<OUString> const & path);
void writeModifications();
void flushModifications();
// must be called with configmgr::lock unacquired; must be called before
// shutdown if writeModifications has ever been called (probably
// indirectly, via removeExtensionXcuFile)
void insertExtensionXcsFile(bool shared, OUString const & fileUri);
void insertExtensionXcuFile(
bool shared, OUString const & fileUri,
Modifications * modifications);
void removeExtensionXcuFile(
OUString const & fileUri, Modifications * modifications);
void insertModificationXcuFile(
OUString const & fileUri,
css::uno::Sequence< OUString > const & includedPaths,
css::uno::Sequence< OUString > const & excludedPaths,
Modifications * modifications);
css::beans::Optional< css::uno::Any >
getExternalValue(std::u16string_view descriptor);
osl::Mutex & getLock() const { return *lock_; }
private:
Components(const Components&) = delete;
Components& operator=(const Components&) = delete;
typedef void FileParser(
OUString const &, int, Data &, Partial const *, Modifications *,
Additions *);
public:
explicit Components(
css::uno::Reference< css::uno::XComponentContext > const & context);
~Components();
private:
void parseFileLeniently(
FileParser * parseFile, OUString const & url, int layer,
Partial const * partial, Modifications * modifications,
Additions * additions);
void parseFiles(
int layer, OUString const & extension, FileParser * parseFile,
OUString const & url, bool recursive);
void parseFileList(
int layer, FileParser * parseFile, std::u16string_view urls,
bool recordAdditions);
void parseXcdFiles(int layer, OUString const & url);
void parseXcsXcuLayer(int layer, OUString const & url);
void parseXcsXcuIniLayer(
int layer, OUString const & url, bool recordAdditions);
void parseResLayer(int layer, std::u16string_view url);
void parseModificationLayer(int layer, OUString const & url);
int getExtensionLayer(bool shared) const;
typedef
config_map<
css::uno::Reference<
css::beans::XPropertySet > >
ExternalServices;
class WriteThread;
enum class ModificationTarget { None, File, Dconf };
css::uno::Reference< css::uno::XComponentContext >
context_;
Data data_;
o3tl::sorted_vector< RootAccess * > roots_;
ExternalServices externalServices_;
rtl::Reference< WriteThread > writeThread_;
int sharedExtensionLayer_;
int userExtensionLayer_;
ModificationTarget modificationTarget_;
OUString modificationFileUrl_;
std::shared_ptr<osl::Mutex> lock_;
};
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */