00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifndef __REFCOUNTED_H__
00014 #define __REFCOUNTED_H__
00015
00016 #include <QMutex>
00017
00020
00021
00022
00025
00026 class RefCounted
00027 {
00028 protected:
00029
00030 long m_nRefCount;
00031 QMutex m_mutex;
00032
00033 protected:
00034
00035
00036
00037 virtual ~RefCounted() {};
00038
00039 public:
00040
00041
00042
00043 RefCounted() : m_nRefCount( 0 )
00044 {
00045 }
00046
00047
00048
00049 long AddRef()
00050 {
00051 m_mutex.lock();
00052 long nRef = (++m_nRefCount);
00053 m_mutex.unlock();
00054
00055 return( nRef );
00056 }
00057
00058
00059
00060 long Release()
00061 {
00062
00063 m_mutex.lock();
00064 long nRef = (--m_nRefCount);
00065 m_mutex.unlock();
00066
00067 if (nRef <= 0)
00068 delete this;
00069
00070 return( nRef );
00071 }
00072 };
00073
00074 #endif