Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Misc/MsqInterrupt.cpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  ***************************************************************** */
24 
25 #include "MsqInterrupt.hpp"
26 #include <signal.h>
27 
28 namespace Mesquite {
29 
30 unsigned MsqInterrupt::instanceCount = 0;
31 bool MsqInterrupt::sawInterrupt = false;
33 
34 extern "C" { typedef void (*msq_sig_handler_t)(int); }
36 
37 
38 extern "C" void msq_sigint_handler( int )
39 {
41  if (oldHandler != SIG_DFL && oldHandler != SIG_IGN)
42  oldHandler( SIGINT );
44 }
45 
46 
48 {
49  oldHandler = signal( SIGINT, &msq_sigint_handler );
51  (oldHandler == SIG_DFL || oldHandler == SIG_IGN))
52  {
53  signal( SIGINT, oldHandler );
54  oldHandler = SIG_ERR;
55  }
56 }
57 
59 {
61  if (instanceCount && SIG_ERR != oldHandler)
62  {
63  signal( SIGINT, oldHandler );
64  oldHandler = SIG_ERR;
65  }
66  sawInterrupt = false;
67 }
68 
70 {
71  sawInterrupt = false;
73  if (instanceCount && SIG_ERR == oldHandler)
74  set_handler();
75 }
76 
77 void MsqInterrupt::allow( MsqError& /*err*/ )
78 {
79  sawInterrupt = false;
81  if (instanceCount && SIG_ERR == oldHandler)
82  set_handler();
83 }
84 
86 {
87  if (!instanceCount)
88  {
89  if (IGNORE != interruptMode)
90  set_handler();
91  sawInterrupt = false;
92  }
93  ++instanceCount;
94 }
95 
97 {
98  if (!--instanceCount && SIG_ERR != oldHandler)
99  {
100  signal( SIGINT, oldHandler );
101  oldHandler = SIG_ERR;
102  }
103  sawInterrupt = false;
104 }
105 
106 } // namespace Mesquite
107 
108 
msq_sig_handler_t oldHandler
Used to hold the error state and return it to the application.
MsqInterrupt()
Constructor, increment instance count.
void(* msq_sig_handler_t)(int)
~MsqInterrupt()
Constructor, decrement instance count.
static void set_interrupt()
Set the interrupt flag.
static void allow(MsqError &err)
Allow Mesquite to register a SIGINT handler.
static void disable(MsqError &err)
Disable Mesquite&#39;s SIGINT handler.
static InterruptMode interruptMode
static void enable(MsqError &err)
Force Mesquite to register SIGINT handler.
void msq_sigint_handler(int)