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