gc++.cxx

00001 #include <gc++.hpp>
00002 #include <common.hpp>
00003 #include <fixed_size_allocator.hpp>
00004 #include <detail/gc++.hpp>
00005 #include <algorithm>
00006 #include <boost/detail/atomic_count.hpp>
00007 
00008 using namespace GCpp;
00009 using namespace std;
00010 
00011 namespace
00012 {
00013 
00014 GCPP_MUTEX pointer_list_mutex;
00015 
00016 boost::detail::atomic_count pause_counter (0);
00017 
00018 } // anonymous namespace
00019 
00020 GCPP_MUTEX GCpp::create_allocator_mutex;
00021 
00022 IntrusiveList<GCBasePointer> GCPointerManager::f_pointers;
00023 size_t GCPointerManager::f_size (0);
00024 
00025 GCBasePointer::GCBasePointer (void* p_storage)
00026 : f_storage (p_storage),
00027   f_state (unknown_tag)
00028 {
00029     GCPointerManager::register_pointer (this);
00030 }
00031 
00032 GCBasePointer::GCBasePointer (const GCBasePointer& p_other)
00033 : f_storage (p_other.f_storage),
00034   f_state (unknown_tag)
00035 {
00036     GCPointerManager::register_pointer (this);
00037 }
00038 
00039 GCBasePointer::~GCBasePointer ()
00040 {
00041     GCPointerManager::forget_pointer (this);
00042     f_storage = 0;
00043 }
00044 
00045 char GCBasePointer::fetch_state ()
00046 {
00047     return FixedSizeAllocatorManager::contains (this) ? leaf_tag : root_tag;
00048 }
00049 
00050 void GCBasePointer::mark ()
00051 {
00052     GC::mark_recursively (this);
00053 }
00054 
00055 GCPointerManager::iterator GCPointerManager::begin ()
00056 {
00057     return f_pointers.begin ();
00058 }
00059 
00060 GCPointerManager::iterator GCPointerManager::end ()
00061 {
00062     return f_pointers.end ();
00063 }
00064 
00065 void GCPointerManager::register_pointer (GCBasePointer* p_item)
00066 {
00067     GCPP_LOCK lck (pointer_list_mutex);
00068     f_pointers.push_back (p_item);
00069 }
00070 
00071 void GCPointerManager::forget_pointer (GCBasePointer* p_item)
00072 {
00073     GCPP_LOCK lck (pointer_list_mutex);
00074     f_pointers.remove (p_item);
00075 }
00076 
00077 bool GCPointerManager::is_pointer (void* p_item)
00078 {
00079     return find (f_pointers.begin (), f_pointers.end (), p_item) != f_pointers.end ();
00080 }
00081 
00082 size_t GCPointerManager::size ()
00083 {
00084     return f_size;
00085 }
00086 
00087 GC_pause::GC_pause ()
00088 {
00089     ++pause_counter;
00090     GC::stop ();
00091 }
00092 
00093 GC_pause::~GC_pause ()
00094 {
00095     if (--pause_counter == 0)
00096         GC::start ();
00097 }

Generated on Thu Dec 27 14:01:59 2007 for GC++ by  doxygen 1.5.4