added mutex to protect reference-counter
git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@766 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* shared_object.h - class sharedObject for use among other objects
|
||||
*
|
||||
* Copyright (c) 2006-2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
@@ -27,28 +28,34 @@
|
||||
#define _SHARED_OBJECT_H
|
||||
|
||||
|
||||
#include <QtCore/QMutex>
|
||||
|
||||
|
||||
class sharedObject
|
||||
{
|
||||
public:
|
||||
sharedObject( void ) :
|
||||
m_reference_count( 1 )
|
||||
m_referenceCount( 1 ),
|
||||
m_lock()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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<class T>
|
||||
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;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user