gc.hh

Go to the documentation of this file.
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___gc_hh___included
00029 #define lestes__std__mem___gc_hh___included
00030 /*! \file
00031   \brief Garbage collector. 
00032   
00033   Declaration of gc class representing garbage collector.
00034   \author pt
00035 */
00036 
00037 #include <lestes/package.hh>
00038 #include <lestes/std/data_types.hh>
00039 
00040 package(lestes);
00041 package(std);
00042 package(mem);
00043 
00044 // forward declarations to avoid cycle
00045 class keystone;
00046 class root_pointer;
00047 
00048 /*!
00049   \brief Initializer for gc.
00050 
00051   Initializes static fields of gc class, before they are used.
00052   Ensures that order of dynamic initialization will not be broken.
00053 */ 
00054 class init_gc {
00055 public:
00056         //! Initializes gc static fields once.
00057         init_gc(void);
00058         //! Performs cleanup to gc static fields once.
00059         ~init_gc(void);
00060 private:
00061         //! Hides copy constructor.
00062         init_gc(const init_gc &);
00063         //! Hides assignment operator.
00064         init_gc &operator=(const init_gc &);
00065 };
00066 
00067 /*!
00068   Static initializer object in each translation unit.
00069   Ensures the proper order of initialization.
00070 */
00071 static init_gc initializer_gc;
00072 
00073 /*!
00074   \brief Garbage collector.
00075 
00076   Provides garbage collector functionality.
00077 */
00078 class gc {
00079 public:
00080         //! Returns number of live root pointers.
00081         static ulint live_roots(void);
00082         //! Returns number of live keystones.
00083         static ulint live_keystones(void);
00084         //! Runs garbage collection.
00085         static void run(void);
00086 private:
00087         //! Initializer accesses gc private methods.
00088         friend class init_gc;
00089         //! Initializes static variables.
00090         static void init(void);
00091         //! Performs cleanup of static variables.
00092         static void cleanup(void);
00093         //! Guard flag to prevent multiple initialization.
00094         static ulint initialized;
00095         //! Root pointer accesses gc private fields for speed.
00096         friend class root_pointer;
00097         //! Keystone accesses gc private fields for speed.
00098         friend class keystone;
00099         //! Doubly linked list of all root pointers.
00100         static root_pointer *roots;
00101         //! Singly linked list of all keystones.
00102         static keystone *keystones;
00103         //! Singly linked list of marked keystones.
00104         static keystone *marked;
00105         //! Hides copy constructor.
00106         gc(const gc &);
00107         //! Hides assignment operator.
00108         gc &operator=(const gc &);
00109 };
00110 
00111 end_package(mem);
00112 end_package(std);
00113 end_package(lestes);
00114 #endif
00115 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:22:34 2007 for lestes by doxygen 1.5.1-20070107