From 74bc575ad1adb8e50eb8fbbef34839f458ec1988 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Tue, 4 Mar 2008 11:28:58 +0000 Subject: [PATCH] added mutex to protect reference-counter git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@766 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/shared_object.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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; } ;