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] - Blame information for rev 207

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
 *  Common routine to implement atexit-like functionality.
3
 */
4
 
5
#include <stddef.h>
6
#include <stdlib.h>
7
#include <reent.h>
8
#include <sys/lock.h>
9
#include "atexit.h"
10
 
11
/* Make this a weak reference to avoid pulling in malloc.  */
12
void * malloc(size_t) _ATTRIBUTE((__weak__));
13
 
14
/*
15
 * Register a function to be performed at exit or on shared library unload.
16
 */
17
 
18
int
19
_DEFUN (__register_exitproc,
20
        (type, fn, arg, d),
21
        int type _AND
22
        void (*fn) (void) _AND
23
        void *arg _AND
24
        void *d)
25
{
26
  struct _on_exit_args * args;
27
  register struct _atexit *p;
28
 
29
#ifndef __SINGLE_THREAD__
30
  __LOCK_INIT(static, lock);
31
 
32
  __lock_acquire(lock);
33
#endif
34
 
35
  p = _GLOBAL_REENT->_atexit;
36
  if (p == NULL)
37
    _GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0;
38
  if (p->_ind >= _ATEXIT_SIZE)
39
    {
40
#ifndef _ATEXIT_DYNAMIC_ALLOC
41
      return -1;
42
#else
43
      /* Don't dynamically allocate the atexit array if malloc is not
44
         available.  */
45
      if (!malloc)
46
        return -1;
47
 
48
      p = (struct _atexit *) malloc (sizeof *p);
49
      if (p == NULL)
50
        {
51
#ifndef __SINGLE_THREAD__
52
          __lock_release(lock);
53
#endif
54
          return -1;
55
        }
56
      p->_ind = 0;
57
      p->_next = _GLOBAL_REENT->_atexit;
58
      _GLOBAL_REENT->_atexit = p;
59
#ifndef _REENT_SMALL
60
      p->_on_exit_args._fntypes = 0;
61
      p->_on_exit_args._is_cxa = 0;
62
#endif
63
#endif
64
    }
65
 
66
  if (type != __et_atexit)
67
    {
68
#ifdef _REENT_SMALL
69
      args = p->_on_exit_args_ptr;
70
      if (args == NULL)
71
        {
72
          if (malloc)
73
            args = malloc (sizeof * p->_on_exit_args_ptr);
74
 
75
          if (args == NULL)
76
            {
77
#ifndef __SINGLE_THREAD__
78
              __lock_release(lock);
79
#endif
80
              return -1;
81
            }
82
          args->_fntypes = 0;
83
          args->_is_cxa = 0;
84
          p->_on_exit_args_ptr = args;
85
        }
86
#else
87
      args = &p->_on_exit_args;
88
#endif
89
      args->_fnargs[p->_ind] = arg;
90
      args->_fntypes |= (1 << p->_ind);
91
      args->_dso_handle[p->_ind] = d;
92
      if (type == __et_cxa)
93
        args->_is_cxa |= (1 << p->_ind);
94
    }
95
  p->_fns[p->_ind++] = fn;
96
#ifndef __SINGLE_THREAD__
97
  __lock_release(lock);
98
#endif
99
  return 0;
100
}

powered by: WebSVN 2.1.0

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