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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [stdlib/] [__call_atexit.c] - Blame information for rev 158

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*
2
 * COmmon routine to call call registered atexit-like routines.
3
 */
4
 
5
 
6
#include <stdlib.h>
7
#include <reent.h>
8
#include "atexit.h"
9
 
10
/*
11
 * Call registered exit handlers.  If D is null then all handlers are called,
12
 * otherwise only the handlers from that DSO are called.
13
 */
14
 
15
void
16
_DEFUN (__call_exitprocs, (code, d),
17
        int code _AND _PTR d)
18
{
19
  register struct _atexit *p;
20
  struct _atexit **lastp;
21
  register struct _on_exit_args * args;
22
  register int n;
23
  int i;
24
  void (*fn) (void);
25
 
26
 restart:
27
 
28
  p = _GLOBAL_REENT->_atexit;
29
  lastp = &_GLOBAL_REENT->_atexit;
30
  while (p)
31
    {
32
#ifdef _REENT_SMALL
33
      args = p->_on_exit_args_ptr;
34
#else
35
      args = &p->_on_exit_args;
36
#endif
37
      for (n = p->_ind - 1; n >= 0; n--)
38
        {
39
          int ind;
40
 
41
          i = 1 << n;
42
 
43
          /* Skip functions not from this dso.  */
44
          if (d && (!args || args->_dso_handle[n] != d))
45
            continue;
46
 
47
          /* Remove the function now to protect against the
48
             function calling exit recursively.  */
49
          fn = p->_fns[n];
50
          if (n == p->_ind - 1)
51
            p->_ind--;
52
          else
53
            p->_fns[n] = NULL;
54
 
55
          /* Skip functions that have already been called.  */
56
          if (!fn)
57
            continue;
58
 
59
          ind = p->_ind;
60
 
61
          /* Call the function.  */
62
          if (!args || (args->_fntypes & i) == 0)
63
            fn ();
64
          else if ((args->_is_cxa & i) == 0)
65
            (*((void (*)(int, _PTR)) fn))(code, args->_fnargs[n]);
66
          else
67
            (*((void (*)(_PTR)) fn))(args->_fnargs[n]);
68
 
69
          /* The function we called call atexit and registered another
70
             function (or functions).  Call these new functions before
71
             continuing with the already registered functions.  */
72
          if (ind != p->_ind || *lastp != p)
73
            goto restart;
74
        }
75
 
76
#ifndef _ATEXIT_DYNAMIC_ALLOC
77
      break;
78
#else
79
      /* Move to the next block.  Free empty blocks except the last one,
80
         which is part of _GLOBAL_REENT.  */
81
      if (p->_ind == 0 && p->_next)
82
        {
83
          /* Remove empty block from the list.  */
84
          *lastp = p->_next;
85
#ifdef _REENT_SMALL
86
          if (args)
87
            free (args);
88
#endif
89
          free (p);
90
          p = *lastp;
91
        }
92
      else
93
        {
94
          lastp = &p->_next;
95
          p = p->_next;
96
        }
97
#endif
98
    }
99
}

powered by: WebSVN 2.1.0

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