summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-07-25 10:26:51 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-07-25 12:13:26 +0200
commitab12ae777b8213f2a3a8ed9a744adb82a1f75e32 (patch)
tree5b17cb85266c7618b18c48f71f4cbadf8e400f8d /svl
parent8a843f7e98dfe6bfb04e91e5b16e3a1df18fbf58 (diff)
A bit of RAII
Change-Id: I58fb16f7e2c4c30212605b667cfd3f79a3dc7d4a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137400 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/undo/undo.cxx26
1 files changed, 10 insertions, 16 deletions
diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx
index 2424a9141a78..1b2c2e8b71b6 100644
--- a/svl/source/undo/undo.cxx
+++ b/svl/source/undo/undo.cxx
@@ -263,14 +263,15 @@ namespace svl::undo::impl
~UndoManagerGuard();
- void clear()
+ struct ResetGuard {
+ ResetGuard(osl::ResettableMutexGuard& r) : rGuard(r) {}
+ ~ResetGuard() { rGuard.reset(); }
+ osl::ResettableMutexGuard& rGuard;
+ };
+ ResetGuard clear()
{
m_aGuard.clear();
- }
-
- void reset()
- {
- m_aGuard.reset();
+ return ResetGuard(m_aGuard);
}
void cancelNotifications()
@@ -706,17 +707,14 @@ bool SfxUndoManager::ImplUndo( SfxUndoContext* i_contextOrNull )
{
// clear the guard/mutex before calling into the SfxUndoAction - this can be an extension-implemented UNO component
// nowadays ...
- aGuard.clear();
+ auto aResetGuard(aGuard.clear());
if ( i_contextOrNull != nullptr )
pAction->UndoWithContext( *i_contextOrNull );
else
pAction->Undo();
- aGuard.reset();
}
catch( ... )
{
- aGuard.reset();
-
// in theory, somebody might have tampered with all of *m_xData while the mutex was unlocked. So, see if
// we still find pAction in our current Undo array
size_t nCurAction = 0;
@@ -818,17 +816,14 @@ bool SfxUndoManager::ImplRedo( SfxUndoContext* i_contextOrNull )
{
// clear the guard/mutex before calling into the SfxUndoAction - this can be an extension-implemented UNO component
// nowadays ...
- aGuard.clear();
+ auto aResetGuard(aGuard.clear());
if ( i_contextOrNull != nullptr )
pAction->RedoWithContext( *i_contextOrNull );
else
pAction->Redo();
- aGuard.reset();
}
catch( ... )
{
- aGuard.reset();
-
// in theory, somebody might have tampered with all of *m_xData while the mutex was unlocked. So, see if
// we still find pAction in our current Undo array
size_t nCurAction = 0;
@@ -875,10 +870,9 @@ bool SfxUndoManager::Repeat( SfxRepeatTarget &rTarget )
if ( !m_xData->pActUndoArray->maUndoActions.empty() )
{
SfxUndoAction* pAction = m_xData->pActUndoArray->maUndoActions.back().pAction.get();
- aGuard.clear();
+ auto aResetGuard(aGuard.clear());
if ( pAction->CanRepeat( rTarget ) )
pAction->Repeat( rTarget );
- aGuard.reset(); // allow clearing in guard dtor
return true;
}