OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [stdlib/] [__atexit.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*
/*
 *  Common routine to implement atexit-like functionality.
 *  Common routine to implement atexit-like functionality.
 */
 */
 
 
#include <stddef.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdlib.h>
#include <reent.h>
#include <reent.h>
#include <sys/lock.h>
#include <sys/lock.h>
#include "atexit.h"
#include "atexit.h"
 
 
/* Make this a weak reference to avoid pulling in malloc.  */
/* Make this a weak reference to avoid pulling in malloc.  */
void * malloc(size_t) _ATTRIBUTE((__weak__));
void * malloc(size_t) _ATTRIBUTE((__weak__));
 
 
/*
/*
 * Register a function to be performed at exit or on shared library unload.
 * Register a function to be performed at exit or on shared library unload.
 */
 */
 
 
int
int
_DEFUN (__register_exitproc,
_DEFUN (__register_exitproc,
        (type, fn, arg, d),
        (type, fn, arg, d),
        int type _AND
        int type _AND
        void (*fn) (void) _AND
        void (*fn) (void) _AND
        void *arg _AND
        void *arg _AND
        void *d)
        void *d)
{
{
  struct _on_exit_args * args;
  struct _on_exit_args * args;
  register struct _atexit *p;
  register struct _atexit *p;
 
 
#ifndef __SINGLE_THREAD__
#ifndef __SINGLE_THREAD__
  __LOCK_INIT(static, lock);
  __LOCK_INIT(static, lock);
 
 
  __lock_acquire(lock);
  __lock_acquire(lock);
#endif
#endif
 
 
  p = _GLOBAL_REENT->_atexit;
  p = _GLOBAL_REENT->_atexit;
  if (p == NULL)
  if (p == NULL)
    _GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0;
    _GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0;
  if (p->_ind >= _ATEXIT_SIZE)
  if (p->_ind >= _ATEXIT_SIZE)
    {
    {
#ifndef _ATEXIT_DYNAMIC_ALLOC
#ifndef _ATEXIT_DYNAMIC_ALLOC
      return -1;
      return -1;
#else
#else
      /* Don't dynamically allocate the atexit array if malloc is not
      /* Don't dynamically allocate the atexit array if malloc is not
         available.  */
         available.  */
      if (!malloc)
      if (!malloc)
        return -1;
        return -1;
 
 
      p = (struct _atexit *) malloc (sizeof *p);
      p = (struct _atexit *) malloc (sizeof *p);
      if (p == NULL)
      if (p == NULL)
        {
        {
#ifndef __SINGLE_THREAD__
#ifndef __SINGLE_THREAD__
          __lock_release(lock);
          __lock_release(lock);
#endif
#endif
          return -1;
          return -1;
        }
        }
      p->_ind = 0;
      p->_ind = 0;
      p->_next = _GLOBAL_REENT->_atexit;
      p->_next = _GLOBAL_REENT->_atexit;
      _GLOBAL_REENT->_atexit = p;
      _GLOBAL_REENT->_atexit = p;
#ifndef _REENT_SMALL
#ifndef _REENT_SMALL
      p->_on_exit_args._fntypes = 0;
      p->_on_exit_args._fntypes = 0;
      p->_on_exit_args._is_cxa = 0;
      p->_on_exit_args._is_cxa = 0;
#endif
#endif
#endif
#endif
    }
    }
 
 
  if (type != __et_atexit)
  if (type != __et_atexit)
    {
    {
#ifdef _REENT_SMALL
#ifdef _REENT_SMALL
      args = p->_on_exit_args_ptr;
      args = p->_on_exit_args_ptr;
      if (args == NULL)
      if (args == NULL)
        {
        {
          if (malloc)
          if (malloc)
            args = malloc (sizeof * p->_on_exit_args_ptr);
            args = malloc (sizeof * p->_on_exit_args_ptr);
 
 
          if (args == NULL)
          if (args == NULL)
            {
            {
#ifndef __SINGLE_THREAD__
#ifndef __SINGLE_THREAD__
              __lock_release(lock);
              __lock_release(lock);
#endif
#endif
              return -1;
              return -1;
            }
            }
          args->_fntypes = 0;
          args->_fntypes = 0;
          args->_is_cxa = 0;
          args->_is_cxa = 0;
          p->_on_exit_args_ptr = args;
          p->_on_exit_args_ptr = args;
        }
        }
#else
#else
      args = &p->_on_exit_args;
      args = &p->_on_exit_args;
#endif
#endif
      args->_fnargs[p->_ind] = arg;
      args->_fnargs[p->_ind] = arg;
      args->_fntypes |= (1 << p->_ind);
      args->_fntypes |= (1 << p->_ind);
      args->_dso_handle[p->_ind] = d;
      args->_dso_handle[p->_ind] = d;
      if (type == __et_cxa)
      if (type == __et_cxa)
        args->_is_cxa |= (1 << p->_ind);
        args->_is_cxa |= (1 << p->_ind);
    }
    }
  p->_fns[p->_ind++] = fn;
  p->_fns[p->_ind++] = fn;
#ifndef __SINGLE_THREAD__
#ifndef __SINGLE_THREAD__
  __lock_release(lock);
  __lock_release(lock);
#endif
#endif
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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