Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4HadSignalHandler.cc
Go to the documentation of this file.
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#if 0
28#include "G4HadSignalHandler.hh"
29
30namespace G4HadSignalHandler_local
31{
32 extern "C"
33 {
34 void HandleIt(int i);
35 static void (*G4HadSignalHandler_initial)(int);
36 }
37}
38
39using namespace std;
40
41G4ThreadLocal std::vector<sighandler_t> *G4HadSignalHandler::theCache = 0;
42G4ThreadLocal bool G4HadSignalHandler::registered = false;
43
44G4HadSignalHandler::G4HadSignalHandler(sighandler_t aNew)
45{
46 if (!theCache) theCache = new std::vector<sighandler_t>;
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
56G4HadSignalHandler::~G4HadSignalHandler()
57{
58 theCache->clear();
59 signal (SIGSEGV, G4HadSignalHandler_local::G4HadSignalHandler_initial);
60 registered = false;
61}
62
63void G4HadSignalHandler_local::HandleIt(int i)
64{
65 static G4ThreadLocal int *iii_p = 0 ;
66 if (!iii_p)
67 {
68 iii_p = new int ;
69 *iii_p = G4HadSignalHandler::theCache->size()-1 ;
70 }
71 int &iii = *iii_p;
72 for(int c=iii; c!=-1; c--)
73 {
74 iii--;
75 //Andrea Dotti (13Jan2013): change for G4MT
76 (G4HadSignalHandler::theCache->operator[](c))(i);
77 //G4HadSignalHandler::theCache[c](i);
78 }
79 std::cerr << "callback to user-defined or default signal handler"<<endl;
80 signal (SIGSEGV, G4HadSignalHandler_local::G4HadSignalHandler_initial);
81 raise(i);
82}
83
84#endif
#define G4ThreadLocal
Definition: tls.hh:77