summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-04-04 11:26:53 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-04-04 13:21:09 +0200
commit6eefe3a29df4b0862a455a2d057e4a7d88457c71 (patch)
treef6d50d6d4bc5687438ab89abdc878381128ff587
parentd33a43a76c3ad6d38f7c2dca0ff5386ee5264bce (diff)
Introduce ResettableMutexGuardScopedReleaser
And use it to guarantee reretting a guard, without having to do that explicitly in exception handlers. Change-Id: I4727cb5b7f37b25e203396957797d24a093e0797 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165775 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--desktop/source/deployment/registry/package/dp_package.cxx9
-rw-r--r--include/osl/mutex.hxx21
2 files changed, 22 insertions, 8 deletions
diff --git a/desktop/source/deployment/registry/package/dp_package.cxx b/desktop/source/deployment/registry/package/dp_package.cxx
index d5c1feeb4992..494ce437e1e9 100644
--- a/desktop/source/deployment/registry/package/dp_package.cxx
+++ b/desktop/source/deployment/registry/package/dp_package.cxx
@@ -808,14 +808,11 @@ void BackendImpl::PackageImpl::processPackage_(
// can occur if the main thread calls isRegistered() on this
// package or any of its parents. So, temporarily release
// this package's mutex while registering the child package.
- guard.clear();
+ osl::ResettableMutexGuardScopedReleaser releaser(guard);
xPackage->registerPackage( startup, xSubAbortChannel, xCmdEnv );
- guard.reset();
}
catch (const Exception &)
{
- guard.reset();
-
//We even try a rollback if the user cancelled the action (CommandAbortedException)
//in order to prevent invalid database entries.
Any exc( ::cppu::getCaughtException() );
@@ -866,10 +863,6 @@ void BackendImpl::PackageImpl::processPackage_(
::cppu::throwException(exc);
}
}
- catch (...) {
- guard.reset();
- throw;
- }
data.items.emplace_back(xPackage->getURL(),
xPackage->getPackageType()->getMediaType());
diff --git a/include/osl/mutex.hxx b/include/osl/mutex.hxx
index 481a2bb55002..ca75cc9fb2dc 100644
--- a/include/osl/mutex.hxx
+++ b/include/osl/mutex.hxx
@@ -252,9 +252,30 @@ namespace osl
}
};
+#ifdef LIBO_INTERNAL_ONLY
+ // A RAII helper to allow exception-safe scoped release of an acquired object
+ template<class ResettableGuard_t>
+ class ResettableGuardScopedReleaser
+ {
+ public:
+ ResettableGuardScopedReleaser(ResettableGuard_t& r)
+ : m_rResettableGuard(r)
+ {
+ m_rResettableGuard.clear();
+ }
+ ~ResettableGuardScopedReleaser() { m_rResettableGuard.reset(); }
+
+ private:
+ ResettableGuard_t& m_rResettableGuard;
+ };
+#endif
+
typedef Guard<Mutex> MutexGuard;
typedef ClearableGuard<Mutex> ClearableMutexGuard;
typedef ResettableGuard< Mutex > ResettableMutexGuard;
+#ifdef LIBO_INTERNAL_ONLY
+ typedef ResettableGuardScopedReleaser<ResettableMutexGuard> ResettableMutexGuardScopedReleaser;
+#endif
}
#endif // INCLUDED_OSL_MUTEX_HXX