summaryrefslogtreecommitdiff
path: root/include/osl
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 /include/osl
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>
Diffstat (limited to 'include/osl')
-rw-r--r--include/osl/mutex.hxx21
1 files changed, 21 insertions, 0 deletions
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