summaryrefslogtreecommitdiff
path: root/framework/inc
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-03-17 16:14:27 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-03-17 16:52:34 +0100
commitab3acb7ef79fcae8776b8d1ce0e81da5698ef516 (patch)
tree0dad3a5d6c6897887cc8ff5c6837d83b7e89a070 /framework/inc
parent803a8a04e980d24bf6c336e4416615a49614367f (diff)
Consolidate framework::{Read,Write}Guard
...now that it is obvious that they both do the same Change-Id: I6878acca4750ef4204fe32a695b6d9e1c5140115
Diffstat (limited to 'framework/inc')
-rw-r--r--framework/inc/services/layoutmanager.hxx2
-rw-r--r--framework/inc/threadhelp/guard.hxx71
-rw-r--r--framework/inc/threadhelp/readguard.hxx169
-rw-r--r--framework/inc/threadhelp/writeguard.hxx165
4 files changed, 71 insertions, 336 deletions
diff --git a/framework/inc/services/layoutmanager.hxx b/framework/inc/services/layoutmanager.hxx
index 6f5bef666b70..c1b84654c6b8 100644
--- a/framework/inc/services/layoutmanager.hxx
+++ b/framework/inc/services/layoutmanager.hxx
@@ -22,8 +22,6 @@
#include <threadhelp/threadhelpbase.hxx>
#include <threadhelp/resetableguard.hxx>
-#include <threadhelp/writeguard.hxx>
-#include <threadhelp/readguard.hxx>
#include <macros/xinterface.hxx>
#include <macros/xtypeprovider.hxx>
#include <properties.h>
diff --git a/framework/inc/threadhelp/guard.hxx b/framework/inc/threadhelp/guard.hxx
new file mode 100644
index 000000000000..9ba1f4a16df8
--- /dev/null
+++ b/framework/inc/threadhelp/guard.hxx
@@ -0,0 +1,71 @@
+/* -*- 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 .
+ */
+
+#ifndef INCLUDED_FRAMEWORK_INC_THREADHELP_GUARD_HXX
+#define INCLUDED_FRAMEWORK_INC_THREADHELP_GUARD_HXX
+
+#include <sal/config.h>
+
+#include <boost/noncopyable.hpp>
+
+#include <threadhelp/lockhelper.hxx>
+
+namespace framework{
+
+class Guard : private boost::noncopyable
+{
+public:
+ Guard( LockHelper& rLock )
+ : m_pLock ( &rLock )
+ , m_locked(false)
+ {
+ lock();
+ }
+
+ ~Guard()
+ {
+ unlock();
+ }
+
+ void lock()
+ {
+ if (!m_locked) {
+ m_pLock->acquire();
+ m_locked = true;
+ }
+ }
+
+ void unlock()
+ {
+ if (m_locked) {
+ m_pLock->release();
+ m_locked = false;
+ }
+ }
+
+private:
+ LockHelper* m_pLock;
+ bool m_locked;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/inc/threadhelp/readguard.hxx b/framework/inc/threadhelp/readguard.hxx
deleted file mode 100644
index 4f9f07ec0bdd..000000000000
--- a/framework/inc/threadhelp/readguard.hxx
+++ /dev/null
@@ -1,169 +0,0 @@
-/* -*- 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 .
- */
-
-#ifndef INCLUDED_FRAMEWORK_INC_THREADHELP_READGUARD_HXX
-#define INCLUDED_FRAMEWORK_INC_THREADHELP_READGUARD_HXX
-
-#include <boost/noncopyable.hpp>
-#include <threadhelp/lockhelper.hxx>
-
-#include <sal/types.h>
-
-
-namespace framework{
-
-/*-************************************************************************************************************
- @short implement a guard to set read locks
- @descr This guard should be used to set a lock for reading object internal member.
- Nobody can control it but don't use member after successfully locking for writing!
- We never need a own mutex to safe our internal member access - because
- a guard is used as function-local member only. There exist no multithreaded access to it really ...
-
- @attention To prevent us against wrong using, the default ctor, copy ctor and the =operator are maked private!
-
- @implements -
-
- @devstatus ready to use
-*//*-*************************************************************************************************************/
-class ReadGuard : private boost::noncopyable
-{
-
- // public methods
-
- public:
-
- /*-****************************************************************************************************
- @short ctor
- @descr These ctors initialize the guard with a reference to used lock member of object to protect.
- Null isn't allowed as value!
-
- @seealso -
-
- @param "pLock" ,reference to used lock member of object to protect
- @param "rLock" ,reference to used lock member of object to protect
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- inline ReadGuard( LockHelper* pLock )
- : m_pLock ( pLock )
- , m_bLocked ( sal_False )
- {
- lock();
- }
-
-
- inline ReadGuard( LockHelper& rLock )
- : m_pLock ( &rLock )
- , m_bLocked ( sal_False )
- {
- lock();
- }
-
- /*-****************************************************************************************************
- @short dtor
- @descr We unlock the used lock member automaticly if user forget it.
-
- @seealso -
-
- @param -
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- inline ~ReadGuard()
- {
- unlock();
- }
-
- /*-****************************************************************************************************
- @short set read lock
- @descr Call this method to set the read lock. The call will block till all current threads are synchronized!
-
- @seealso method unlock()
-
- @param -
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- inline void lock()
- {
- if( m_bLocked == sal_False )
- {
- m_pLock->acquire();
- m_bLocked = sal_True;
- }
- }
-
- /*-****************************************************************************************************
- @short unset read lock
- @descr Call this method to unlock the rw-lock temp.!
- Normaly we do it at dtor automaticly for you ...
-
- @seealso method lock()
-
- @param -
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- inline void unlock()
- {
- if( m_bLocked == sal_True )
- {
- m_pLock->release();
- m_bLocked = sal_False;
- }
- }
-
-
- // private methods
-
- private:
-
- /*-****************************************************************************************************
- @short disable using of these functions!
- @descr It's not allowed to use this methods. Different problem can occur otherwise.
- Thats why we disable it by make it private.
-
- @seealso other ctor
-
- @param -
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- ReadGuard();
-
-
- // private member
-
- private:
-
- LockHelper* m_pLock ; /// reference to lock-member of protected object
- sal_Bool m_bLocked ; /// protection against multiple lock calls without unlock!
-
-}; // class ReadGuard
-
-} // namespace framework
-
-#endif // INCLUDED_FRAMEWORK_INC_THREADHELP_READGUARD_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/inc/threadhelp/writeguard.hxx b/framework/inc/threadhelp/writeguard.hxx
deleted file mode 100644
index 516ea926d9f3..000000000000
--- a/framework/inc/threadhelp/writeguard.hxx
+++ /dev/null
@@ -1,165 +0,0 @@
-/* -*- 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 .
- */
-
-#ifndef INCLUDED_FRAMEWORK_INC_THREADHELP_WRITEGUARD_HXX
-#define INCLUDED_FRAMEWORK_INC_THREADHELP_WRITEGUARD_HXX
-
-#include <boost/noncopyable.hpp>
-#include <threadhelp/lockhelper.hxx>
-
-
-namespace framework{
-
-/*-************************************************************************************************************
- @short implement a guard to set write locks
- @descr This guard should be used to set a lock for reading AND writing object internal member.
- We never need a own mutex to safe our internal member access - because
- a guard is used as function-local member only. There exist no multithreaded access to it really ...
-
- @attention To prevent us against wrong using, the default ctor, copy ctor and the =operator are maked private!
-
- @implements -
-
- @devstatus ready to use
-*//*-*************************************************************************************************************/
-class WriteGuard : private boost::noncopyable
-{
-
- // public methods
-
- public:
-
- /*-****************************************************************************************************
- @short ctor
- @descr These ctors initialize the guard with a reference to used lock member of object to protect.
- Null isn't allowed as value!
-
- @seealso -
-
- @param "pLock" ,reference to used lock member of object to protect
- @param "rLock" ,reference to used lock member of object to protect
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- inline WriteGuard( LockHelper* pLock )
- : m_pLock ( pLock )
- , m_locked(false)
- {
- lock();
- }
-
-
- inline WriteGuard( LockHelper& rLock )
- : m_pLock ( &rLock )
- , m_locked(false)
- {
- lock();
- }
-
- /*-****************************************************************************************************
- @short dtor
- @descr We unlock the used lock member automaticly if user forget it.
-
- @seealso -
-
- @param -
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- inline ~WriteGuard()
- {
- unlock();
- }
-
- /*-****************************************************************************************************
- @short set write lock
- @descr Call this method to set the write lock. The call will block till all current threads are synchronized!
-
- @seealso method unlock()
-
- @param -
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- inline void lock()
- {
- if (!m_locked) {
- // Acquire write access and set return state.
- // Mode is set later if it was successful!
- m_pLock->acquire();
- m_locked = true;
- }
- }
-
- /*-****************************************************************************************************
- @short unset write lock
- @descr Call this method to unlock the rw-lock temp.!
- Normaly we do it at dtor automaticly for you ...
-
- @seealso method lock()
-
- @param -
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- inline void unlock()
- {
- if (m_locked) {
- m_pLock->release();
- m_locked = false;
- }
- }
-
- // private methods
-
- private:
-
- /*-****************************************************************************************************
- @short disable using of these functions!
- @descr It's not allowed to use this methods. Different problem can occur otherwise.
- Thats why we disable it by make it private.
-
- @seealso other ctor
-
- @param -
- @return -
-
- @onerror -
- *//*-*****************************************************************************************************/
- WriteGuard();
-
-
- // private member
-
- private:
-
- LockHelper* m_pLock ; /// reference to lock-member of protected object
- bool m_locked;
-
-}; // class WriteGuard
-
-} // namespace framework
-
-#endif // INCLUDED_FRAMEWORK_INC_THREADHELP_WRITEGUARD_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */