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
REGISTER_PRIMITIVE_TYPE(Object);
-#ifdef _DEBUG
-boost::mutex Object::m_DebugMutex;
-#endif /* _DEBUG */
-
/**
* Default constructor for the Object class.
*/
*/
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 */
+++ /dev/null
-/******************************************************************************
- * 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;
- }
-}
*/
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;