SIMLIB/C++ 3.09
Loading...
Searching...
No Matches
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
17namespace simlib3 {
18
20
21static const int MAX_ATEXIT = 10; // for internal use it is enough
22static int counter = 0; // internal module counter
24
25// used in SIMLIB
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
36}
37
38// used here
39static 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
50 string(0) {
51 counter++;
52 DEBUG(DBG_MODULE,("MODULE#%d initialization",counter));
53}
54
55// set module id string
56int SIMLIB_module::Init(const char *s) {
57 string = s;
58 return counter;
59}
60
61// destructor --- last one calls atexit functions
63 DEBUG(DBG_MODULE,("MODULE#%d cleanup %s",counter, string?string:""));
64 if(--counter == 0)
66}
67
68}
69
70// end
int Init(const char *s)
Definition: atexit.cc:56
Internal header file for SIMLIB/C++.
#define DBG_ATEXIT
Definition: internal.h:128
#define SIMLIB_internal_error()
Definition: internal.h:167
#define DBG_MODULE
Definition: internal.h:127
#define DEBUG(c, f)
Definition: internal.h:105
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition: algloop.cc:32
SIMLIB_IMPLEMENTATION
Definition: algloop.cc:34
static void SIMLIB_atexit_call()
Definition: atexit.cc:39
void(* SIMLIB_atexit_function_t)()
Definition: internal.h:150
void SIMLIB_atexit(SIMLIB_atexit_function_t p)
Definition: atexit.cc:26
static int counter
Definition: atexit.cc:22
static const int MAX_ATEXIT
Definition: atexit.cc:21
static SIMLIB_atexit_function_t atexit_array[MAX_ATEXIT]
Definition: atexit.cc:23
Main SIMLIB/C++ interface.