1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | #ifndef G4HadSignalHandler_off |
---|
27 | |
---|
28 | #include "G4HadSignalHandler.hh" |
---|
29 | |
---|
30 | |
---|
31 | namespace G4HadSignalHandler_local |
---|
32 | { |
---|
33 | extern "C" |
---|
34 | { |
---|
35 | void HandleIt(int i); |
---|
36 | static void (*G4HadSignalHandler_initial)(int); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | using namespace std; |
---|
41 | |
---|
42 | std::vector<sighandler_t> G4HadSignalHandler::theCache; |
---|
43 | bool G4HadSignalHandler::registered = false; |
---|
44 | |
---|
45 | G4HadSignalHandler::G4HadSignalHandler(sighandler_t aNew) |
---|
46 | { |
---|
47 | if(!registered) |
---|
48 | { |
---|
49 | G4HadSignalHandler_local::G4HadSignalHandler_initial = |
---|
50 | signal(SIGSEGV, G4HadSignalHandler_local::HandleIt); |
---|
51 | registered = true; |
---|
52 | } |
---|
53 | theCache.push_back(aNew); |
---|
54 | } |
---|
55 | |
---|
56 | G4HadSignalHandler::~G4HadSignalHandler() |
---|
57 | { |
---|
58 | theCache.clear(); |
---|
59 | signal (SIGSEGV, G4HadSignalHandler_local::G4HadSignalHandler_initial); |
---|
60 | registered = false; |
---|
61 | } |
---|
62 | |
---|
63 | void G4HadSignalHandler_local::HandleIt(int i) |
---|
64 | { |
---|
65 | static int iii=G4HadSignalHandler::theCache.size()-1; |
---|
66 | for(int c=iii; c!=-1; c--) |
---|
67 | { |
---|
68 | iii--; |
---|
69 | G4HadSignalHandler::theCache[c](i); |
---|
70 | } |
---|
71 | std::cerr << "callback to user-defined or default signal handler"<<endl; |
---|
72 | signal (SIGSEGV, G4HadSignalHandler_local::G4HadSignalHandler_initial); |
---|
73 | raise(i); |
---|
74 | } |
---|
75 | |
---|
76 | #endif |
---|