]> granicus.if.org Git - icinga2/commitdiff
Allow locks to be inlined
authorGunnar Beutner <gunnar@beutner.name>
Wed, 12 Nov 2014 05:33:20 +0000 (06:33 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 12 Nov 2014 05:33:20 +0000 (06:33 +0100)
refs #7622

lib/base/CMakeLists.txt
lib/base/object.cpp
lib/base/object.hpp
lib/base/objectlock.cpp [deleted file]
lib/base/objectlock.hpp

index e9f388f120cc6c563ce1fd0fb341e02616e1f088..293dea4523499da9ef8b2d7f0d761dc69c43d3d1 100644 (file)
@@ -26,7 +26,7 @@ set(base_SOURCES
   application.cpp application.thpp array.cpp configerror.cpp console.cpp context.cpp
   convert.cpp debuginfo.cpp dictionary.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp
   exception.cpp fifo.cpp filelogger.cpp filelogger.thpp initialize.cpp json.cpp logger.cpp logger.thpp
-  netstring.cpp networkstream.cpp object.cpp objectlock.cpp primitivetype.cpp process.cpp
+  netstring.cpp networkstream.cpp object.cpp primitivetype.cpp process.cpp
   ringbuffer.cpp scriptfunction.cpp scriptfunctionwrapper.cpp
   scriptutils.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
   statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp 
index b36bd4a59683677ff3e857e68e8e041a30f577dc..5d2b31f7ca9d9daf4bc00bfdf52261e513ce2bae 100644 (file)
@@ -25,10 +25,6 @@ using namespace icinga;
 
 REGISTER_PRIMITIVE_TYPE(Object);
 
-#ifdef _DEBUG
-boost::mutex Object::m_DebugMutex;
-#endif /* _DEBUG */
-
 /**
  * Default constructor for the Object class.
  */
@@ -53,8 +49,7 @@ Object::~Object(void)
  */
 bool Object::OwnsLock(void) const
 {
-       boost::mutex::scoped_lock lock(m_DebugMutex);
-
+       // TODO: barrier before reading m_Locked
        return (m_Locked && m_LockOwner == boost::this_thread::get_id());
 }
 #endif /* _DEBUG */
index 2b6bb8c93a865d3dd940b818ce180590d46687c6..fbaaf8640b57bdef6aaf81e83a4d6db022739b49 100644 (file)
@@ -109,7 +109,6 @@ private:
        mutable ThinMutex m_Mutex;
 
 #ifdef _DEBUG
-       static boost::mutex m_DebugMutex;
        mutable bool m_Locked;
        mutable boost::thread::id m_LockOwner;
 #endif /* _DEBUG */
diff --git a/lib/base/objectlock.cpp b/lib/base/objectlock.cpp
deleted file mode 100644 (file)
index 17a7a49..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
-
-#include "base/objectlock.hpp"
-#include "base/debug.hpp"
-
-using namespace icinga;
-
-ObjectLock::ObjectLock(void)
-       : m_Object(NULL), m_Locked(false)
-{ }
-
-ObjectLock::~ObjectLock(void)
-{
-       Unlock();
-}
-
-ObjectLock::ObjectLock(const Object::Ptr& object)
-       : m_Object(object.get()), m_Locked(false)
-{
-       if (m_Object)
-               Lock();
-}
-
-ObjectLock::ObjectLock(const Object *object)
-       : m_Object(object), m_Locked(false)
-{
-       if (m_Object)
-               Lock();
-}
-
-void ObjectLock::Lock(void)
-{
-       ASSERT(!m_Locked && m_Object != NULL);
-       ASSERT(!m_Object->OwnsLock());
-
-       m_Object->m_Mutex.Lock();
-       m_Locked = true;
-
-#ifdef _DEBUG
-       {
-               boost::mutex::scoped_lock lock(Object::m_DebugMutex);
-               m_Object->m_Locked = true;
-               m_Object->m_LockOwner = boost::this_thread::get_id();
-       }
-#endif /* _DEBUG */
-}
-
-void ObjectLock::Unlock(void)
-{
-#ifdef _DEBUG
-       {
-               boost::mutex::scoped_lock lock(Object::m_DebugMutex);
-               if (m_Locked)
-                       m_Object->m_Locked = false;
-       }
-#endif /* _DEBUG */
-
-       if (m_Locked) {
-               m_Object->m_Mutex.Unlock();
-               m_Locked = false;
-       }
-}
index bcb293830f3c2669610d5c4bddacbbf031e1ad5c..3aa0e39b191fa36c3dfd3e186da0b6eccb5598a4 100644 (file)
@@ -30,13 +30,56 @@ namespace icinga
  */
 struct I2_BASE_API ObjectLock {
 public:
-       ObjectLock(void);
-       ObjectLock(const Object::Ptr& object);
-       ObjectLock(const Object *object);
-       ~ObjectLock(void);
+       inline ObjectLock(void)
+               : m_Object(NULL), m_Locked(false)
+       { }
 
-       void Lock(void);
-       void Unlock(void);
+       inline ~ObjectLock(void)
+       {
+               Unlock();
+       }
+
+       inline ObjectLock(const Object::Ptr& object)
+               : m_Object(object.get()), m_Locked(false)
+       {
+               if (m_Object)
+                       Lock();
+       }
+
+       inline ObjectLock(const Object *object)
+               : m_Object(object), m_Locked(false)
+       {
+               if (m_Object)
+                       Lock();
+       }
+
+       inline void Lock(void)
+       {
+               ASSERT(!m_Locked && m_Object != NULL);
+               ASSERT(!m_Object->OwnsLock());
+
+               m_Object->m_Mutex.Lock();
+               m_Locked = true;
+
+#ifdef _DEBUG
+               m_Object->m_Locked = true;
+               // TODO: barrier after writing m_Locked
+               m_Object->m_LockOwner = boost::this_thread::get_id();
+#endif /* _DEBUG */
+       }
+
+       inline void Unlock(void)
+       {
+       #ifdef _DEBUG
+               if (m_Locked)
+                       m_Object->m_Locked = false;
+       #endif /* _DEBUG */
+
+               if (m_Locked) {
+                       m_Object->m_Mutex.Unlock();
+                       m_Locked = false;
+               }
+       }
 
 private:
        const Object *m_Object;