diff --git a/include/shared_object.h b/include/shared_object.h index d0d45a230..399373296 100644 --- a/include/shared_object.h +++ b/include/shared_object.h @@ -2,6 +2,7 @@ * shared_object.h - class sharedObject for use among other objects * * Copyright (c) 2006-2007 Javier Serrano Polo + * Copyright (c) 2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -27,28 +28,34 @@ #define _SHARED_OBJECT_H +#include class sharedObject { public: sharedObject( void ) : - m_reference_count( 1 ) + m_referenceCount( 1 ), + m_lock() { } template static T * ref( T * _object ) { + _object->m_lock.lock(); // TODO: Use QShared - ++_object->m_reference_count; + ++_object->m_referenceCount; + _object->m_lock.unlock(); return( _object ); } template static void unref( T * _object ) { - bool delete_object = --_object->m_reference_count == 0; + _object->m_lock.lock(); + bool delete_object = --_object->m_referenceCount <= 0; + _object->m_lock.unlock(); if ( delete_object ) { delete _object; @@ -57,7 +64,8 @@ public: private: - unsigned m_reference_count; + int m_referenceCount; + QMutex m_lock; } ;