Back to index

plt-scheme  4.2.1
Defines | Functions
fnls.c File Reference
#include "../utils/splay.c"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define Tree   Fnl
#define Splay_Item(t)   ((unsigned long)t->p)
#define Set_Splay_Item(t, v)   (t)->p = (void *)v
#define splay   fnl_splay
#define splay_insert   fnl_splay_insert
#define splay_delete   fnl_splay_delete

Functions

void GC_set_finalizer (void *p, int tagged, int level, void(*f)(void *p, void *data), void *data, void(**oldf)(void *p, void *data), void **olddata)
static void reset_finalizer_tree (GCTYPE *gc)

Define Documentation

#define Set_Splay_Item (   t,
 
)    (t)->p = (void *)v

Definition at line 16 of file fnls.c.

#define splay   fnl_splay

Definition at line 17 of file fnls.c.

#define splay_delete   fnl_splay_delete

Definition at line 19 of file fnls.c.

#define splay_insert   fnl_splay_insert

Definition at line 18 of file fnls.c.

#define Splay_Item (   t)    ((unsigned long)t->p)

Definition at line 15 of file fnls.c.

#define Tree   Fnl

Definition at line 14 of file fnls.c.


Function Documentation

void GC_set_finalizer ( void p,
int  tagged,
int  level,
void(*)(void *p, void *data f,
void data,
void(**)(void *p, void *data oldf,
void **  olddata 
)

Definition at line 25 of file fnls.c.

{
  GCTYPE *gc = GC_get_GC();
  Fnl *fnl;

  if (!is_finalizable_page(gc, p)) {
    /* Never collected. Don't finalize it. */
    if (oldf) *oldf = NULL;
    if (olddata) *olddata = NULL;
    return;
  }

  gc->splayed_finalizers = fnl_splay((unsigned long)p, gc->splayed_finalizers);
  fnl = gc->splayed_finalizers;
  if (fnl && (fnl->p == p)) {
    if (oldf) *oldf = fnl->f;
    if (olddata) *olddata = fnl->data;
    if (f) {
      fnl->f = f;
      fnl->data = data;
      fnl->eager_level = level;
    } else {
      /* remove finalizer */
      if (fnl->prev)
        fnl->prev->next = fnl->next;
      else
        gc->finalizers = fnl->next;
      if (fnl->next)
        fnl->next->prev = fnl->prev;

      --gc->num_fnls;
      gc->splayed_finalizers = fnl_splay_delete((unsigned long)p, gc->splayed_finalizers);
    }
    return;
  }

  if (oldf) *oldf = NULL;
  if (olddata) *olddata = NULL;

  if (!f)
    return;

  /* Allcation might trigger GC, so we use park: */
  gc->park[0] = p;
  gc->park[1] = data;

  fnl = (Fnl *)GC_malloc_atomic(sizeof(Fnl));
  memset(fnl, 0, sizeof(Fnl));

  p = gc->park[0];
  data = gc->park[1];
  gc->park[0] = NULL;
  gc->park[1] = NULL;


  fnl->p = p;
  fnl->f = f;
  fnl->data = data;
  fnl->eager_level = level;
  fnl->tagged = tagged;

#if CHECKS
  {
    MPage *m;

    m = find_page(p);

    if (tagged) {
      if (m->type != MTYPE_TAGGED) {
        GCPRINT(GCOUTF, "Not tagged: %lx (%d)\n", 
            (long)p, m->type);
        CRASH(4);
      }
    } else {
      if (m->type != MTYPE_XTAGGED) {
        GCPRINT(GCOUTF, "Not xtagged: %lx (%d)\n", 
            (long)p, m->type);
        CRASH(5);
      }
      if (m->flags & MFLAG_BIGBLOCK)
        fnl->size = m->u.size;
      else
        fnl->size = ((long *)p)[-1];
    }
  }
#endif

  /* push finalizer */
  fnl->next = gc->finalizers;
  fnl->prev = NULL;
  if (gc->finalizers) {
    gc->finalizers->prev = fnl;
  }
  gc->finalizers = fnl;

  gc->splayed_finalizers = fnl_splay_insert((unsigned long)p, fnl, gc->splayed_finalizers);

  gc->num_fnls++;
}

Here is the call graph for this function:

static void reset_finalizer_tree ( GCTYPE gc) [static]

Definition at line 127 of file fnls.c.

{
  Fnl *fnl;
  Fnl *prev = NULL;

  gc->splayed_finalizers = NULL;

  for (fnl = gc->finalizers; fnl; fnl = fnl->next) {
    fnl->prev = prev;
    gc->splayed_finalizers = fnl_splay_insert((unsigned long)fnl->p, fnl, gc->splayed_finalizers);
    prev = fnl;
  }
}

Here is the caller graph for this function: