Panda3D
|
00001 // Filename: cachedTypedWritableReferenceCount.h 00002 // Created by: drose (25Jan05) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef CACHEDTYPEDWRITABLEREFERENCECOUNT_H 00016 #define CACHEDTYPEDWRITABLEREFERENCECOUNT_H 00017 00018 #include "pandabase.h" 00019 00020 #include "typedWritableReferenceCount.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Class : CachedTypedWritableReferenceCount 00024 // Description : This is a special extension to ReferenceCount that 00025 // includes dual reference counts: the standard 00026 // reference count number, which includes all references 00027 // to the object, and a separate number (the cache 00028 // reference count) that counts the number of references 00029 // to the object just within its cache alone. When 00030 // get_ref_count() == get_cache_ref_count(), the object 00031 // is not referenced outside the cache. 00032 // 00033 // The cache refs must be explicitly maintained; there 00034 // is no PointerTo<> class to maintain the cache 00035 // reference counts automatically. The cache reference 00036 // count is automatically included in the overall 00037 // reference count: calling cache_ref() and 00038 // cache_unref() automatically calls ref() and unref(). 00039 //////////////////////////////////////////////////////////////////// 00040 class EXPCL_PANDA_PUTIL CachedTypedWritableReferenceCount : public TypedWritableReferenceCount { 00041 protected: 00042 INLINE CachedTypedWritableReferenceCount(); 00043 INLINE CachedTypedWritableReferenceCount(const CachedTypedWritableReferenceCount ©); 00044 INLINE void operator = (const CachedTypedWritableReferenceCount ©); 00045 INLINE ~CachedTypedWritableReferenceCount(); 00046 00047 PUBLISHED: 00048 INLINE int get_cache_ref_count() const; 00049 INLINE void cache_ref() const; 00050 INLINE bool cache_unref() const; 00051 INLINE bool test_ref_count_integrity() const; 00052 00053 protected: 00054 INLINE void cache_unref_only() const; 00055 bool do_test_ref_count_integrity() const; 00056 00057 private: 00058 AtomicAdjust::Integer _cache_ref_count; 00059 00060 public: 00061 static TypeHandle get_class_type() { 00062 return _type_handle; 00063 } 00064 00065 static void init_type() { 00066 TypedWritableReferenceCount::init_type(); 00067 register_type(_type_handle, "CachedTypedWritableReferenceCount", 00068 TypedWritableReferenceCount::get_class_type()); 00069 } 00070 00071 private: 00072 static TypeHandle _type_handle; 00073 }; 00074 00075 template<class RefCountType> 00076 INLINE void cache_unref_delete(RefCountType *ptr); 00077 00078 #include "cachedTypedWritableReferenceCount.I" 00079 00080 #endif