OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-dev/] [fsf-gcc-snapshot-1-mar-12/] [or1k-gcc/] [boehm-gc/] [gc_dlopen.c] - Diff between revs 721 and 783

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 721 Rev 783
/*
/*
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
 * Copyright (c) 1997 by Silicon Graphics.  All rights reserved.
 * Copyright (c) 1997 by Silicon Graphics.  All rights reserved.
 * Copyright (c) 2000 by Hewlett-Packard Company.  All rights reserved.
 * Copyright (c) 2000 by Hewlett-Packard Company.  All rights reserved.
 *
 *
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 *
 *
 * Permission is hereby granted to use or copy this program
 * Permission is hereby granted to use or copy this program
 * for any purpose,  provided the above notices are retained on all copies.
 * for any purpose,  provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 * modified is included with the above copyright notice.
 *
 *
 * Original author: Bill Janssen
 * Original author: Bill Janssen
 * Heavily modified by Hans Boehm and others
 * Heavily modified by Hans Boehm and others
 */
 */
 
 
/*
/*
 * This used to be in dyn_load.c.  It was extracted into a separate file
 * This used to be in dyn_load.c.  It was extracted into a separate file
 * to avoid having to link against libdl.{a,so} if the client doesn't call
 * to avoid having to link against libdl.{a,so} if the client doesn't call
 * dlopen.  Of course this fails if the collector is in a dynamic
 * dlopen.  Of course this fails if the collector is in a dynamic
 * library. -HB
 * library. -HB
 */
 */
 
 
#include "private/gc_priv.h"
#include "private/gc_priv.h"
 
 
# if (defined(GC_PTHREADS) && !defined(GC_DARWIN_THREADS)) \
# if (defined(GC_PTHREADS) && !defined(GC_DARWIN_THREADS)) \
      || defined(GC_SOLARIS_THREADS)
      || defined(GC_SOLARIS_THREADS)
 
 
# if defined(dlopen) && !defined(GC_USE_LD_WRAP)
# if defined(dlopen) && !defined(GC_USE_LD_WRAP)
    /* To support various threads pkgs, gc.h interposes on dlopen by     */
    /* To support various threads pkgs, gc.h interposes on dlopen by     */
    /* defining "dlopen" to be "GC_dlopen", which is implemented below.  */
    /* defining "dlopen" to be "GC_dlopen", which is implemented below.  */
    /* However, both GC_FirstDLOpenedLinkMap() and GC_dlopen() use the   */
    /* However, both GC_FirstDLOpenedLinkMap() and GC_dlopen() use the   */
    /* real system dlopen() in their implementation. We first remove     */
    /* real system dlopen() in their implementation. We first remove     */
    /* gc.h's dlopen definition and restore it later, after GC_dlopen(). */
    /* gc.h's dlopen definition and restore it later, after GC_dlopen(). */
#   undef dlopen
#   undef dlopen
# endif
# endif
 
 
  /* Make sure we're not in the middle of a collection, and make        */
  /* Make sure we're not in the middle of a collection, and make        */
  /* sure we don't start any.   Returns previous value of GC_dont_gc.   */
  /* sure we don't start any.   Returns previous value of GC_dont_gc.   */
  /* This is invoked prior to a dlopen call to avoid synchronization    */
  /* This is invoked prior to a dlopen call to avoid synchronization    */
  /* issues.  We can't just acquire the allocation lock, since startup  */
  /* issues.  We can't just acquire the allocation lock, since startup  */
  /* code in dlopen may try to allocate.                                */
  /* code in dlopen may try to allocate.                                */
  /* This solution risks heap growth in the presence of many dlopen     */
  /* This solution risks heap growth in the presence of many dlopen     */
  /* calls in either a multithreaded environment, or if the library     */
  /* calls in either a multithreaded environment, or if the library     */
  /* initialization code allocates substantial amounts of GC'ed memory. */
  /* initialization code allocates substantial amounts of GC'ed memory. */
  /* But I don't know of a better solution.                             */
  /* But I don't know of a better solution.                             */
  static void disable_gc_for_dlopen()
  static void disable_gc_for_dlopen()
  {
  {
    LOCK();
    LOCK();
    while (GC_incremental && GC_collection_in_progress()) {
    while (GC_incremental && GC_collection_in_progress()) {
        GC_collect_a_little_inner(1000);
        GC_collect_a_little_inner(1000);
    }
    }
    ++GC_dont_gc;
    ++GC_dont_gc;
    UNLOCK();
    UNLOCK();
  }
  }
 
 
  /* Redefine dlopen to guarantee mutual exclusion with */
  /* Redefine dlopen to guarantee mutual exclusion with */
  /* GC_register_dynamic_libraries.                     */
  /* GC_register_dynamic_libraries.                     */
  /* Should probably happen for other operating systems, too. */
  /* Should probably happen for other operating systems, too. */
 
 
#include <dlfcn.h>
#include <dlfcn.h>
 
 
#ifdef GC_USE_LD_WRAP
#ifdef GC_USE_LD_WRAP
  void * __wrap_dlopen(const char *path, int mode)
  void * __wrap_dlopen(const char *path, int mode)
#else
#else
  void * GC_dlopen(path, mode)
  void * GC_dlopen(path, mode)
  GC_CONST char * path;
  GC_CONST char * path;
  int mode;
  int mode;
#endif
#endif
{
{
    void * result;
    void * result;
 
 
#   ifndef USE_PROC_FOR_LIBRARIES
#   ifndef USE_PROC_FOR_LIBRARIES
      disable_gc_for_dlopen();
      disable_gc_for_dlopen();
#   endif
#   endif
#   ifdef GC_USE_LD_WRAP
#   ifdef GC_USE_LD_WRAP
      result = (void *)__real_dlopen(path, mode);
      result = (void *)__real_dlopen(path, mode);
#   else
#   else
      result = dlopen(path, mode);
      result = dlopen(path, mode);
#   endif
#   endif
#   ifndef USE_PROC_FOR_LIBRARIES
#   ifndef USE_PROC_FOR_LIBRARIES
      GC_enable(); /* undoes disable_gc_for_dlopen */
      GC_enable(); /* undoes disable_gc_for_dlopen */
#   endif
#   endif
    return(result);
    return(result);
}
}
# endif  /* GC_PTHREADS || GC_SOLARIS_THREADS ... */
# endif  /* GC_PTHREADS || GC_SOLARIS_THREADS ... */
 
 
 
 
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.