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/] [__atexit.c] - Blame information for rev 179

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

Line No. Rev Author Line
1 148 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
 
12
/*
13
 * Register a function to be performed at exit or on shared library unload.
14
 */
15
 
16
int
17
_DEFUN (__register_exitproc,
18
        (type, fn, arg, d),
19
        int type _AND
20
        void (*fn) (void) _AND
21
        void *arg _AND
22
        void *d)
23
{
24
  struct _on_exit_args * args;
25
  register struct _atexit *p;
26
 
27
#ifndef __SINGLE_THREAD__
28
  __LOCK_INIT(static, lock);
29
 
30
  __lock_acquire(lock);
31
#endif
32
 
33
  p = _GLOBAL_REENT->_atexit;
34
  if (p == NULL)
35
    _GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0;
36
  if (p->_ind >= _ATEXIT_SIZE)
37
    {
38
#ifndef _ATEXIT_DYNAMIC_ALLOC
39
      return -1;
40
#else
41
      p = (struct _atexit *) malloc (sizeof *p);
42
      if (p == NULL)
43
        {
44
#ifndef __SINGLE_THREAD__
45
          __lock_release(lock);
46
#endif
47
          return -1;
48
        }
49
      p->_ind = 0;
50
      p->_next = _GLOBAL_REENT->_atexit;
51
      _GLOBAL_REENT->_atexit = p;
52
#ifndef _REENT_SMALL
53
      p->_on_exit_args._fntypes = 0;
54
      p->_on_exit_args._is_cxa = 0;
55
#endif
56
#endif
57
    }
58
 
59
  if (type != __et_atexit)
60
    {
61
#ifdef _REENT_SMALL
62
      args = p->_on_exit_args_ptr;
63
      if (args == NULL)
64
        {
65
          args = malloc (sizeof * p->_on_exit_args_ptr);
66
          if (args == NULL)
67
            {
68
#ifndef __SINGLE_THREAD__
69
              __lock_release(lock);
70
#endif
71
              return -1;
72
            }
73
          args->_fntypes = 0;
74
          args->_is_cxa = 0;
75
          p->_on_exit_args_ptr = args;
76
        }
77
#else
78
      args = &p->_on_exit_args;
79
#endif
80
      args->_fnargs[p->_ind] = arg;
81
      args->_fntypes |= (1 << p->_ind);
82
      args->_dso_handle[p->_ind] = d;
83
      if (type == __et_cxa)
84
        args->_is_cxa |= (1 << p->_ind);
85
    }
86
  p->_fns[p->_ind++] = fn;
87
#ifndef __SINGLE_THREAD__
88
  __lock_release(lock);
89
#endif
90
  return 0;
91
}

powered by: WebSVN 2.1.0

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