00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 #ifndef lestes__std__mem___keystone_hh___included 00029 #define lestes__std__mem___keystone_hh___included 00030 00031 /*! \file 00032 \brief Collectible object. 00033 00034 Declaration of keystone class representing base of garbage collectible classes. 00035 \author pt 00036 */ 00037 #include <lestes/package.hh> 00038 #include <lestes/std/mem/gc.hh> 00039 00040 package(lestes); 00041 package(std); 00042 package(mem); 00043 00044 /*! 00045 Abstract common ancestor of all collectible classes. 00046 Shall only be allocated dynamically. 00047 */ 00048 class keystone { 00049 public: 00050 //! Finalizes the keystone. 00051 virtual ~keystone(void); 00052 //! Enqueues the keystone into marked list. 00053 inline void enqueue(void); 00054 protected: 00055 //! Creates the keystone. 00056 inline keystone(void); 00057 //! Marks the keystone. 00058 virtual void gc_mark(void); 00059 private: 00060 //! Class gc accesses keystone for speed. 00061 friend class gc; 00062 //! Sweeps the keystone. 00063 inline void sweep(void); 00064 //! Next keystone in linked list of all keystones. 00065 keystone *keystones_next; 00066 /*! 00067 \brief Next keystone in mark queue. 00068 00069 If the keystone is not in the mark queue, it is set to this 00070 to distinguish it from the last NULL entry in the queue. 00071 */ 00072 keystone *marked_next; 00073 //! Hides copy constructor. 00074 keystone(const keystone &); 00075 //! Hides assignment operator. 00076 keystone &operator=(const keystone &); 00077 }; 00078 00079 /*! 00080 Creates the keystone. 00081 Links into list of all keystones. 00082 */ 00083 inline keystone::keystone(void): 00084 // insert before first 00085 keystones_next(gc::keystones), 00086 // set as unmarked 00087 marked_next(this) 00088 { 00089 // make first in list 00090 gc::keystones = this; 00091 } 00092 00093 /*! 00094 Enqueues the keystone into marked list if not already marked. 00095 Later it is processed, resulting into recursive marking. 00096 */ 00097 inline void keystone::enqueue(void) { 00098 // already marked 00099 if (marked_next != this) return; 00100 // link into list 00101 marked_next = gc::marked; 00102 gc::marked = this; 00103 } 00104 00105 /*! 00106 Deletes the keystone if not marked, otherwise links again 00107 into the list of all keystones. 00108 */ 00109 inline void keystone::sweep(void) { 00110 // was marked 00111 if (marked_next != this) { 00112 // unmark 00113 marked_next = this; 00114 // link into list of all keystones 00115 keystones_next = gc::keystones; 00116 gc::keystones = this; 00117 } else { 00118 // delete the keystone 00119 delete this; 00120 } 00121 } 00122 00123 end_package(mem); 00124 end_package(std); 00125 end_package(lestes); 00126 #endif 00127 /* vim: set ft=lestes : */
1.5.1-20070107