#ifndef SCM_GC_H
#define SCM_GC_H
-/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
\f
#include "libguile/__scm.h"
#include "libguile/hooks.h"
-
-#if SCM_USE_PTHREAD_THREADS
-# include "libguile/pthread-threads.h"
-#else
-# include "libguile/null-threads.h"
-#endif
+#include "libguile/threads.h"
\f
+/* Cell allocation and garbage collection work rouhgly in the
+ following manner:
+
+ Each thread has a 'freelist', which is a list of available cells.
+ (It actually has two freelists, one for single cells and one for
+ double cells. Everything works analogous for double cells.)
+
+ When a thread wants to allocate a cell and the freelist is empty,
+ it refers to a global list of unswept 'cards'. A card is a small
+ block of cells that are contigous in memory, together with the
+ corresponding mark bits. A unswept card is one where the mark bits
+ are set for cells that have been in use during the last global mark
+ phase, but the unmarked cells of the card have not been scanned and
+ freed yet.
+
+ The thread takes one of the unswept cards and sweeps it, thereby
+ building a new freelist that it then uses. Sweeping a card will
+ call the smob free functions of unmarked cells, for example, and
+ thus, these free functions can run at any time, in any thread.
+
+ When there are no more unswept cards available, the thread performs
+ a global garbage collection. For this, all other threads are
+ stopped. A global mark is performed and all cards are put into the
+ global list of unswept cards. Whennecessary, new cards are
+ allocated and initialized at this time. The other threads are then
+ started again.
+*/
+
typedef struct scm_t_cell
{
SCM word_0;
#define SCM_GC_CARD_N_HEADER_CELLS 1
#define SCM_GC_CARD_N_CELLS 256
-#define SCM_GC_SIZEOF_CARD SCM_GC_CARD_N_CELLS * sizeof (scm_t_cell)
+#define SCM_GC_SIZEOF_CARD SCM_GC_CARD_N_CELLS * sizeof (scm_t_cell)
#define SCM_GC_CARD_BVEC(card) ((scm_t_c_bvec_long *) ((card)->word_0))
#define SCM_GC_SET_CARD_BVEC(card, bvec) \
#define SCM_SET_CELL_OBJECT_2(x, v) SCM_SET_CELL_OBJECT ((x), 2, (v))
#define SCM_SET_CELL_OBJECT_3(x, v) SCM_SET_CELL_OBJECT ((x), 3, (v))
+#define SCM_CELL_OBJECT_LOC(x, n) (SCM_VALIDATE_CELL((x), &SCM_GC_CELL_OBJECT ((x), (n))))
+#define SCM_CARLOC(x) (SCM_CELL_OBJECT_LOC ((x), 0))
+#define SCM_CDRLOC(x) (SCM_CELL_OBJECT_LOC ((x), 1))
+
#define SCM_CELL_TYPE(x) SCM_CELL_WORD_0 (x)
#define SCM_SET_CELL_TYPE(x, t) SCM_SET_CELL_WORD_0 ((x), (t))
* the freelist. Due to this structure, freelist cells are not cons cells
* and thus may not be accessed using SCM_CAR and SCM_CDR. */
-/*
- SCM_FREECELL_P removed ; the semantics are ambiguous with lazy
- sweeping. Could mean "this cell is no longer in use (will be swept)"
- or "this cell has just been swept, and is not yet in use".
- */
-
-#define SCM_FREECELL_P this_macro_has_been_removed_see_gc_header_file
-
#define SCM_FREE_CELL_CDR(x) \
(SCM_GC_CELL_OBJECT ((x), 1))
#define SCM_SET_FREE_CELL_CDR(x, v) \
(SCM_GC_SET_CELL_OBJECT ((x), 1, (v)))
-
-#define SCM_CELL_OBJECT_LOC(x, n) (SCM_VALIDATE_CELL((x), &SCM_GC_CELL_OBJECT ((x), (n))))
-#define SCM_CARLOC(x) (SCM_CELL_OBJECT_LOC ((x), 0))
-#define SCM_CDRLOC(x) (SCM_CELL_OBJECT_LOC ((x), 1))
-
-
-
-
#if (SCM_DEBUG_CELL_ACCESSES == 1)
/* Set this to != 0 if every cell that is accessed shall be checked:
*/
void scm_i_expensive_validation_check (SCM cell);
#endif
-SCM_API scm_t_mutex scm_i_gc_admin_mutex;
+SCM_API scm_i_pthread_mutex_t scm_i_gc_admin_mutex;
+
+#define scm_gc_running_p (SCM_I_CURRENT_THREAD->gc_running_p)
+SCM_API scm_i_pthread_mutex_t scm_i_sweep_mutex;
+
+#ifdef __ia64__
+void *scm_ia64_register_backing_store_base (void);
+void *scm_ia64_ar_bsp (const void *);
+#endif
-SCM_API int scm_block_gc;
-SCM_API int scm_gc_heap_lock;
-SCM_API unsigned int scm_gc_running_p;
-SCM_API scm_t_rec_mutex scm_i_sweep_mutex;
\f
#if (SCM_ENABLE_DEPRECATED == 1)
SCM_API size_t scm_max_segment_size;
-#define SCM_FREELIST_CREATE(key) \
- do { SCM *ls = (SCM *) malloc (sizeof (SCM)); \
- *ls = SCM_EOL; \
- scm_setspecific ((key), ls); } while (0)
-#define SCM_FREELIST_LOC(key) ((SCM *) scm_getspecific (key))
-SCM_API scm_t_key scm_i_freelist;
-SCM_API scm_t_key scm_i_freelist2;
+#define SCM_SET_FREELIST_LOC(key,ptr) scm_i_pthread_setspecific ((key), (ptr))
+#define SCM_FREELIST_LOC(key) ((SCM *) scm_i_pthread_getspecific (key))
+SCM_API scm_i_pthread_key_t scm_i_freelist;
+SCM_API scm_i_pthread_key_t scm_i_freelist2;
SCM_API struct scm_t_cell_type_statistics scm_i_master_freelist;
SCM_API struct scm_t_cell_type_statistics scm_i_master_freelist2;
-
-SCM_API unsigned long scm_gc_cells_swept;
-SCM_API unsigned long scm_gc_cells_collected;
SCM_API unsigned long scm_gc_malloc_collected;
-SCM_API unsigned long scm_gc_ports_collected;
SCM_API unsigned long scm_cells_allocated;
-SCM_API int scm_gc_cell_yield_percentage;
SCM_API int scm_gc_malloc_yield_percentage;
SCM_API unsigned long scm_mallocated;
SCM_API unsigned long scm_mtrigger;
SCM_API SCM scm_object_address (SCM obj);
SCM_API SCM scm_gc_stats (void);
SCM_API SCM scm_gc_live_object_stats (void);
-SCM_API SCM scm_gc_tag_name (SCM tag);
SCM_API SCM scm_gc (void);
SCM_API void scm_gc_for_alloc (struct scm_t_cell_type_statistics *freelist);
SCM_API SCM scm_gc_for_newcell (struct scm_t_cell_type_statistics *master, SCM *freelist);
-SCM_API void scm_igc (const char *what);
+SCM_API void scm_i_gc (const char *what);
SCM_API void scm_gc_mark (SCM p);
SCM_API void scm_gc_mark_dependencies (SCM p);
SCM_API void scm_mark_locations (SCM_STACKITEM x[], unsigned long n);