Changeset 15202


Ignore:
Timestamp:
Feb 9, 2012, 9:20:57 AM (8 years ago)
Author:
gb
Message:

Defer all aspects of gcable-pointer termination until after other
threads have been resumed. This is necessary because some things
that we were doing earlier (sem_destroy, for instance) may try to
do memory operations that may require ownership of a lock owned
by some other thread.

There are some (hopefully minor) consequences of this change: the
GC has to retain an otherwise unreachable lisp XMACPTR object until
the next GC, and some foreign resources might by tied up slightly
longer than they had been in the old scheme.

Location:
trunk/source/lisp-kernel
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/gc-common.c

    r15144 r15202  
    714714     
    715715
    716 void *postGCptrs = NULL;
    717716struct xmacptr *user_postGC_macptrs = NULL;
    718717
    719718
    720 void
    721 postGCfree(void *p)
    722 {
    723   *(void **)p = postGCptrs;
    724   postGCptrs = p;
    725 }
    726719
    727720void
    728721postGCfreexmacptr(struct xmacptr *p)
    729722{
    730   p->class = (LispObj) user_postGC_macptrs;
     723  p->link = (LispObj) user_postGC_macptrs;
    731724  user_postGC_macptrs = p;
    732725}
     
    745738  xmacptr_dispose_fn dfn;
    746739
    747   for (p = postGCptrs; p; p = next) {
    748     next = *((void **)p);
    749     free(p);
    750   }
    751   postGCptrs = NULL;
    752740 
    753741  for (x = user_postGC_macptrs; x; x = xnext) {
    754     xnext = (xmacptr *) (x->class);
    755     flags = x->flags - xmacptr_flag_user_first;
    756     dfn = xmacptr_dispose_functions[flags];
    757     addr = (void *) x->address;
     742    xnext = (xmacptr *) (x->link);
     743    flags = x->flags;
     744    addr = (void *)x->address;
    758745    x->address = 0;
    759746    x->flags = 0;
    760747    x->link = 0;
    761748    x->class = 0;
    762     if (dfn && addr) {
    763       dfn(addr);
     749    if (addr) {
     750      switch(flags) {
     751      case xmacptr_flag_recursive_lock:
     752        destroy_recursive_lock((RECURSIVE_LOCK)addr);
     753        break;
     754      case xmacptr_flag_ptr:
     755        free(addr);
     756        break;
     757      case xmacptr_flag_none:   /* ?? */
     758        break;
     759      case xmacptr_flag_rwlock:
     760        rwlock_destroy((rwlock *)addr);
     761        break;
     762      case xmacptr_flag_semaphore:
     763        destroy_semaphore((void **)&addr);
     764        break;
     765      default:
     766        if ((flags >= xmacptr_flag_user_first) &&
     767            (flags < xmacptr_flag_user_last)) {
     768          flags -= xmacptr_flag_user_first;
     769          dfn = xmacptr_dispose_functions[flags];
     770          if (dfn && addr) {
     771            dfn(addr);
     772          }
     773        }
     774      }
    764775    }
    765776  }
     
    789800{
    790801  LispObj *prev = &(lisp_global(GCABLE_POINTERS)), next, ptr;
    791   xmacptr_flag flag;
    792802  natural dnode;
    793803  xmacptr *x;
     
    802812    } else {
    803813      *prev = x->link;
    804       flag = (xmacptr_flag)(x->flags);
    805814      ptr = x->address;
    806815
    807816      if (ptr) {
    808         switch (flag) {
    809         case xmacptr_flag_recursive_lock:
    810           destroy_recursive_lock((RECURSIVE_LOCK)ptr_from_lispobj(ptr));
    811           break;
    812 
    813         case xmacptr_flag_ptr:
    814           postGCfree((void *)ptr_from_lispobj(ptr));
    815           break;
    816 
    817         case xmacptr_flag_rwlock:
    818           rwlock_destroy((rwlock *)ptr_from_lispobj(ptr));
    819           break;
    820 
    821         case xmacptr_flag_semaphore:
    822           destroy_semaphore((void**)&(x->address));
    823           break;
    824 
    825         default:
    826           if ((flag >= xmacptr_flag_user_first) &&
    827               (flag < xmacptr_flag_user_last)) {
    828             set_n_bits(GCmarkbits,dnode,3);
    829             postGCfreexmacptr(x);
    830             break;
    831           }
    832           /* (warn "unknown xmacptr_flag: ~s" flag) */
    833           /* Unknowd, and perhaps unknowdable. */
    834           /* Fall in: */
    835         case xmacptr_flag_none:
    836           break;
    837         }
     817        set_n_bits(GCmarkbits,dnode,3);
     818        postGCfreexmacptr(x);
    838819      }
    839820    }
     
    11061087      *xprev = xnew;
    11071088    }
    1108     xprev = (struct xmacptr **)(&(xnext->class));
     1089    xprev = (struct xmacptr **)(&(xnext->link));
    11091090  }
    11101091}
  • trunk/source/lisp-kernel/gc.h

    r14807 r15202  
    7474void mark_locative_root(LispObj);
    7575void rmark(LispObj);
    76 void postGCfree(void *);
    7776LispObj *skip_over_ivector(LispObj, LispObj);
    7877void mark_simple_area_range(LispObj *,LispObj *);
  • trunk/source/lisp-kernel/pmcl-kernel.c

    r15191 r15202  
    23592359#if defined(LINUX) || defined(FREEBSD) || defined(SOLARIS)
    23602360#if WORD_SIZE == 64
    2361 typedef Elf64_Dyn Elf_Dyn;
    2362 typedef Elf64_Ehdr Elf_Ehdr;
    2363 typedef Elf64_Shdr Elf_Shdr;
    2364 #else
    2365 typedef Elf32_Dyn Elf_Dyn;
    2366 typedef Elf32_Ehdr Elf_Ehdr;
    2367 typedef Elf32_Shdr Elf_Shdr;
    2368 #endif
    2369 
    2370 Elf_Dyn *
     2361typedef Elf64_Dyn Elf_Dyn_thing;
     2362typedef Elf64_Ehdr Elf_Ehdr_thing;
     2363typedef Elf64_Shdr Elf_Shdr_thing;
     2364#else
     2365typedef Elf32_Dyn Elf_Dyn_thing;
     2366typedef Elf32_Ehdr Elf_Ehdr_thing;
     2367typedef Elf32_Shdr Elf_Shdr_thing;
     2368#endif
     2369
     2370Elf_Dyn_thing *
    23712371get_executable_dynamic_entries()
    23722372{
    23732373#ifndef CCLSHARED
    2374   extern Elf_Dyn _DYNAMIC[];
     2374  extern Elf_Dyn_thing _DYNAMIC[];
    23752375  return _DYNAMIC;
    23762376#else
     
    24262426{
    24272427  int tag;
    2428   Elf_Dyn *dp;
     2428  Elf_Dyn_thing *dp;
    24292429
    24302430  if (cached_r_debug == NULL) {
  • trunk/source/lisp-kernel/thread_manager.c

    r15191 r15202  
    385385  destroy_semaphore((void **)&m->signal);
    386386#endif
    387   postGCfree((void *)(m->malloced_ptr));
     387  free((void *)(m->malloced_ptr));
    388388}
    389389
     
    735735#ifdef USE_POSIX_SEMAPHORES
    736736    sem_destroy((sem_t *)*s);
    737     if (lisp_global(IN_GC)) {
    738       postGCfree(*s);
    739     } else {
    740       free(*s);
    741     }
     737    free(*s);   
    742738#endif
    743739#ifdef USE_MACH_SEMAPHORES
     
    27422738  destroy_semaphore((void **)&rw->writer_signal);
    27432739#endif
    2744   postGCfree((void *)(rw->malloced_ptr));
     2740  free((void *)(rw->malloced_ptr));
    27452741}
    27462742
Note: See TracChangeset for help on using the changeset viewer.