Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
28 #include "G4HadSignalHandler.hh"
29 
30 namespace G4HadSignalHandler_local
31 {
32  extern "C"
33  {
34  void HandleIt(int i);
36  }
37 }
38 
39 using namespace std;
40 
41 G4ThreadLocal std::vector<sighandler_t> *G4HadSignalHandler::theCache = 0;
43 
45 {
46  if (!theCache) theCache = new std::vector<sighandler_t>;
47  if(!registered)
48  {
50  signal(SIGSEGV, G4HadSignalHandler_local::HandleIt);
51  registered = true;
52  }
53  theCache->push_back(aNew);
54 }
55 
57 {
58  theCache->clear();
60  registered = false;
61 }
62 
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;
81  raise(i);
82 }
83 
84 #endif
static G4ThreadLocal std::vector< sighandler_t > * theCache
G4HadSignalHandler(sighandler_t aNew)
#define G4ThreadLocal
Definition: tls.hh:89
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static void(* G4HadSignalHandler_initial)(int)
void(* sighandler_t)(int)
tuple c
Definition: test.py:13
static G4ThreadLocal bool registered
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData