SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
atexit.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
//! \file atexit.cc Implementation of global objects for cleanup
3
//
4
// Copyright (c) 1991-2004 Petr Peringer
5
//
6
// This library is licensed under GNU Library GPL. See the file COPYING.
7
//
8
9
//
10
// atexit module implements module init/clean count and calls all
11
// registered functions AFTER all modules are cleaned
12
//
13
14
#include "
simlib.h
"
15
#include "
internal.h
"
16
17
namespace
simlib3
{
18
19
SIMLIB_IMPLEMENTATION
;
20
21
static
const
int
MAX_ATEXIT
= 10;
// for internal use it is enough
22
static
int
counter
= 0;
// internal module counter
23
static
SIMLIB_atexit_function_t
atexit_array
[
MAX_ATEXIT
] = { 0, };
24
25
// used in SIMLIB
26
void
SIMLIB_atexit
(
SIMLIB_atexit_function_t
p) {
27
DEBUG
(
DBG_ATEXIT
,(
"SIMLIB_atexit(%p)"
, p ));
28
int
i;
29
for
(i=0; i<
MAX_ATEXIT
; i++) {
30
if
(
atexit_array
[i]==0)
break
;
31
}
32
if
(i<
MAX_ATEXIT
)
33
atexit_array
[i]=p;
34
else
35
SIMLIB_internal_error
();
36
}
37
38
// used here
39
static
void
SIMLIB_atexit_call
() {
40
DEBUG
(
DBG_ATEXIT
,(
"ATEXIT:"
));
41
for
(
int
i=0; i<
MAX_ATEXIT
; i++)
42
if
(
atexit_array
[i]) {
43
DEBUG
(
DBG_ATEXIT
,(
"ATEXIT_CALL#%d: %p "
, i,
atexit_array
[i]));
44
atexit_array
[i]();
45
}
46
}
47
48
// constructor --- count module and initialize
49
SIMLIB_module::SIMLIB_module
():
50
string
(0) {
51
counter
++;
52
DEBUG
(
DBG_MODULE
,(
"MODULE#%d initialization"
,
counter
));
53
}
54
55
// set module id string
56
int
SIMLIB_module::Init
(
const
char
*s) {
57
string
= s;
58
return
counter
;
59
}
60
61
// destructor --- last one calls atexit functions
62
SIMLIB_module::~SIMLIB_module
() {
63
DEBUG
(
DBG_MODULE
,(
"MODULE#%d cleanup %s"
,
counter
,
string
?
string
:
""
));
64
if
(--
counter
== 0)
65
SIMLIB_atexit_call
();
66
}
67
68
}
69
70
// end
simlib3::SIMLIB_module::string
const char * string
Definition
internal.h:61
simlib3::SIMLIB_module::~SIMLIB_module
~SIMLIB_module()
Definition
atexit.cc:62
simlib3::SIMLIB_module::SIMLIB_module
SIMLIB_module()
Definition
atexit.cc:49
simlib3::SIMLIB_module::Init
int Init(const char *s)
Definition
atexit.cc:56
internal.h
Internal header file for SIMLIB/C++.
DBG_ATEXIT
#define DBG_ATEXIT
Definition
internal.h:128
SIMLIB_internal_error
#define SIMLIB_internal_error()
Definition
internal.h:167
DBG_MODULE
#define DBG_MODULE
Definition
internal.h:127
DEBUG
#define DEBUG(c, f)
Definition
internal.h:105
simlib3
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition
algloop.cc:32
simlib3::SIMLIB_IMPLEMENTATION
SIMLIB_IMPLEMENTATION
Definition
algloop.cc:34
simlib3::SIMLIB_atexit_call
static void SIMLIB_atexit_call()
Definition
atexit.cc:39
simlib3::SIMLIB_atexit
void SIMLIB_atexit(SIMLIB_atexit_function_t p)
Definition
atexit.cc:26
simlib3::SIMLIB_atexit_function_t
void(*) SIMLIB_atexit_function_t()
Definition
internal.h:150
simlib3::counter
static int counter
Definition
atexit.cc:22
simlib3::MAX_ATEXIT
static const int MAX_ATEXIT
Definition
atexit.cc:21
simlib3::atexit_array
static SIMLIB_atexit_function_t atexit_array[MAX_ATEXIT]
Definition
atexit.cc:23
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0