Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MsqInterrupt Class Reference

Class to watch for user-interrupt (SIGINT, ctrl-C) More...

#include <MsqInterrupt.hpp>

Public Member Functions

 MsqInterrupt ()
 Constructor, increment instance count. More...
 
 ~MsqInterrupt ()
 Constructor, decrement instance count. More...
 
 MsqInterrupt ()
 Constructor, increment instance count. More...
 
 ~MsqInterrupt ()
 Constructor, decrement instance count. More...
 

Static Public Member Functions

static void disable (MsqError &err)
 Disable Mesquite's SIGINT handler. More...
 
static void allow (MsqError &err)
 Allow Mesquite to register a SIGINT handler. More...
 
static void enable (MsqError &err)
 Force Mesquite to register SIGINT handler. More...
 
static bool interrupt ()
 Check if an interrupt was seen. More...
 
static void clear ()
 Clear the interrupt flag. More...
 
static void set_interrupt ()
 Set the interrupt flag. More...
 
static void set_handler ()
 
static void disable (MsqError &err)
 Disable Mesquite's SIGINT handler. More...
 
static void allow (MsqError &err)
 Allow Mesquite to register a SIGINT handler. More...
 
static void enable (MsqError &err)
 Force Mesquite to register SIGINT handler. More...
 
static bool interrupt ()
 Check if an interrupt was seen. More...
 
static void clear ()
 Clear the interrupt flag. More...
 
static void set_interrupt ()
 Set the interrupt flag. More...
 
static void set_handler ()
 

Private Types

enum  InterruptMode {
  CATCH, IGNORE, AUTO, CATCH,
  IGNORE, AUTO
}
 
enum  InterruptMode {
  CATCH, IGNORE, AUTO, CATCH,
  IGNORE, AUTO
}
 

Private Member Functions

void * operator new (size_t size)
 
 MsqInterrupt (const MsqInterrupt &)
 
MsqInterruptoperator= (const MsqInterrupt &)
 
void * operator new (size_t size)
 
 MsqInterrupt (const MsqInterrupt &)
 
MsqInterruptoperator= (const MsqInterrupt &)
 

Static Private Attributes

static InterruptMode interruptMode = MsqInterrupt::AUTO
 
static unsigned instanceCount = 0
 
static bool sawInterrupt = false
 

Detailed Description

Class to watch for user-interrupt (SIGINT, ctrl-C)

A class to watch for SIGINT.

Creating an instance of the class ensures that the Mesquite handler for SIGINT is registered. When all instances are destroyed, the Mesquite handler is removed. The intent is that each interruptable API declare an instance on the stack. This way the handler is automatically unregistered when the API returns. For example: void my_api( MsqError& err ) { MsqInterrupt interrupt; ... //do stuff return; }

Definition at line 51 of file includeLinks/MsqInterrupt.hpp.

Member Enumeration Documentation

Constructor & Destructor Documentation

Constructor, increment instance count.

If instance count was zero, register SIGINT handler

Definition at line 85 of file Misc/MsqInterrupt.cpp.

References MsqInterrupt::IGNORE, MsqInterrupt::instanceCount, MsqInterrupt::interruptMode, MsqInterrupt::sawInterrupt, and MsqInterrupt::set_handler().

86 {
87  if (!instanceCount)
88  {
89  if (IGNORE != interruptMode)
90  set_handler();
91  sawInterrupt = false;
92  }
93  ++instanceCount;
94 }
static InterruptMode interruptMode

Here is the call graph for this function:

Constructor, decrement instance count.

If instance count goes to zero, remove SIGINT handler

Definition at line 96 of file Misc/MsqInterrupt.cpp.

References MsqInterrupt::instanceCount, Mesquite::oldHandler, and MsqInterrupt::sawInterrupt.

97 {
98  if (!--instanceCount && SIG_ERR != oldHandler)
99  {
100  signal( SIGINT, oldHandler );
101  oldHandler = SIG_ERR;
102  }
103  sawInterrupt = false;
104 }
msq_sig_handler_t oldHandler
MsqInterrupt ( const MsqInterrupt )
private

Constructor, increment instance count.

If instance count was zero, register SIGINT handler

Constructor, decrement instance count.

If instance count goes to zero, remove SIGINT handler

MsqInterrupt ( const MsqInterrupt )
private

Member Function Documentation

void allow ( MsqError err)
static

Allow Mesquite to register a SIGINT handler.

Definition at line 77 of file Misc/MsqInterrupt.cpp.

References MsqInterrupt::AUTO, MsqInterrupt::instanceCount, MsqInterrupt::interruptMode, Mesquite::oldHandler, MsqInterrupt::sawInterrupt, and MsqInterrupt::set_handler().

78 {
79  sawInterrupt = false;
81  if (instanceCount && SIG_ERR == oldHandler)
82  set_handler();
83 }
msq_sig_handler_t oldHandler
static InterruptMode interruptMode

Here is the call graph for this function:

static void allow ( MsqError err)
static

Allow Mesquite to register a SIGINT handler.

static void clear ( )
inlinestatic

Clear the interrupt flag.

Definition at line 65 of file includeLinks/MsqInterrupt.hpp.

References MsqInterrupt::sawInterrupt.

65 { sawInterrupt = false; }
static void clear ( )
inlinestatic

Clear the interrupt flag.

Definition at line 65 of file src/Misc/MsqInterrupt.hpp.

References MsqInterrupt::sawInterrupt.

65 { sawInterrupt = false; }
static void disable ( MsqError err)
static

Disable Mesquite's SIGINT handler.

void disable ( MsqError err)
static

Disable Mesquite's SIGINT handler.

Definition at line 58 of file Misc/MsqInterrupt.cpp.

References MsqInterrupt::IGNORE, MsqInterrupt::instanceCount, MsqInterrupt::interruptMode, Mesquite::oldHandler, and MsqInterrupt::sawInterrupt.

59 {
61  if (instanceCount && SIG_ERR != oldHandler)
62  {
63  signal( SIGINT, oldHandler );
64  oldHandler = SIG_ERR;
65  }
66  sawInterrupt = false;
67 }
msq_sig_handler_t oldHandler
static InterruptMode interruptMode
static void enable ( MsqError err)
static

Force Mesquite to register SIGINT handler.

void enable ( MsqError err)
static

Force Mesquite to register SIGINT handler.

Definition at line 69 of file Misc/MsqInterrupt.cpp.

References MsqInterrupt::CATCH, MsqInterrupt::instanceCount, MsqInterrupt::interruptMode, Mesquite::oldHandler, MsqInterrupt::sawInterrupt, and MsqInterrupt::set_handler().

70 {
71  sawInterrupt = false;
73  if (instanceCount && SIG_ERR == oldHandler)
74  set_handler();
75 }
msq_sig_handler_t oldHandler
static InterruptMode interruptMode

Here is the call graph for this function:

static bool interrupt ( )
inlinestatic

Check if an interrupt was seen.

Definition at line 63 of file includeLinks/MsqInterrupt.hpp.

References MsqInterrupt::sawInterrupt.

Referenced by TerminationCriterion::terminate().

63 { return sawInterrupt; }

Here is the caller graph for this function:

static bool interrupt ( )
inlinestatic

Check if an interrupt was seen.

Definition at line 63 of file src/Misc/MsqInterrupt.hpp.

References MsqInterrupt::sawInterrupt.

63 { return sawInterrupt; }
void* operator new ( size_t  size)
private
void* operator new ( size_t  size)
private
MsqInterrupt& operator= ( const MsqInterrupt )
private
MsqInterrupt& operator= ( const MsqInterrupt )
private
static void set_handler ( )
static
void set_handler ( )
static

Definition at line 47 of file Misc/MsqInterrupt.cpp.

References MsqInterrupt::AUTO, MsqInterrupt::interruptMode, Mesquite::msq_sigint_handler(), and Mesquite::oldHandler.

Referenced by MsqInterrupt::allow(), MsqInterrupt::enable(), Mesquite::msq_sigint_handler(), and MsqInterrupt::MsqInterrupt().

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 }
msq_sig_handler_t oldHandler
static InterruptMode interruptMode
void msq_sigint_handler(int)

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_interrupt ( )
inlinestatic

Set the interrupt flag.

Definition at line 67 of file includeLinks/MsqInterrupt.hpp.

References MsqInterrupt::sawInterrupt.

Referenced by Mesquite::msq_sigint_handler().

67 { sawInterrupt = true; }

Here is the caller graph for this function:

static void set_interrupt ( )
inlinestatic

Set the interrupt flag.

Definition at line 67 of file src/Misc/MsqInterrupt.hpp.

References MsqInterrupt::sawInterrupt.

67 { sawInterrupt = true; }

Member Data Documentation


The documentation for this class was generated from the following files: