Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
#include "implement.h"
32
 
33
 
34
/*
35
    SYSTEM ATEXIT FUNCTION
36
 
37
    The macro sys_atexit calls the system atexit function.  The macro
38
    FS_ATEXIT may be defined on machines where atexit is not defined.
39
*/
40
 
41
#ifndef FS_ATEXIT
42
#define FS_ATEXIT	0
43
#endif
44
 
45
#if ( FS_ATEXIT == 1 )
46
extern "C" int on_exit ( EXITER, char * ) ;
47
#define sys_atexit( X )	( on_exit ) ( X, NULL )
48
#else
49
#define sys_atexit( X )	( atexit ) ( X )
50
#endif
51
 
52
 
53
/*
54
    LIST OF TERMINATION FUNCTIONS
55
 
56
    This list represents all the termination functions which are to be
57
    called at the end of a program.
58
*/
59
 
60
DTOR_LIST *__TCPPLUS_dtors = 0 ;
61
 
62
 
63
/*
64
    CALL ALL TERMINATION FUNCTIONS
65
 
66
    This routine scans down the list of all termination functions calling
67
    each in turn.
68
*/
69
 
70
void __TCPPLUS_term ()
71
{
72
    DTOR_LIST *p = __TCPPLUS_dtors ;
73
    __TCPPLUS_dtors = 0 ;
74
    while ( p ) {
75
	CLASS *q = p->arg ;
76
	if ( q ) {
77
	    // Destructor call
78
	    p->func ( q, 2 ) ;
79
	} else {
80
	    // atexit function call
81
	    ( ( EXITER ) p->func ) () ;
82
	}
83
	p = p->next ;
84
    }
85
    return ;
86
}
87
 
88
 
89
/*
90
    INITIALISE TERMINATION FUNCTIONS
91
 
92
    This routine uses the system atexit to register the function
93
    __TCPPLUS_term as being called at the end of the program.
94
*/
95
 
96
void __TCPPLUS_init ()
97
{
98
    static int started = 0 ;
99
    if ( !started ) {
100
	sys_atexit ( __TCPPLUS_term ) ;
101
	started = 1 ;
102
    }
103
    return ;
104
}
105
 
106
 
107
/*
108
    REPLACEMENT ATEXIT FUNCTION
109
 
110
    This routine is a replacement for the system atexit function which
111
    works in conjunction with the destructor lists.
112
*/
113
 
114
int __TCPPLUS_atexit ( EXITER fn )
115
{
116
    DTOR_LIST *p = ( DTOR_LIST * ) malloc ( sizeof ( DTOR_LIST ) ) ;
117
    if ( p == NULL ) return ( -1 ) ;
118
    p->next = __TCPPLUS_dtors ;
119
    p->arg = NULL ;
120
    p->func = ( DESTRUCTOR ) fn ;
121
    __TCPPLUS_dtors = p ;
122
    __TCPPLUS_init () ;
123
    return ( 0 ) ;
124
}