MOAB: Mesh Oriented datABase  (version 5.4.1)
MBMesquite::MsqInterrupt Class Reference

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

#include <MsqInterrupt.hpp>

Public Member Functions

 MsqInterrupt ()
 ~MsqInterrupt ()

Static Public Member Functions

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

Private Types

enum  InterruptMode { CATCH, IGNORE, AUTO }

Private Member Functions

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 52 of file MsqInterrupt.hpp.


Member Enumeration Documentation

Enumerator:
CATCH 
IGNORE 
AUTO 

Definition at line 88 of file MsqInterrupt.hpp.

    {
        CATCH,
        IGNORE,
        AUTO
    };

Constructor & Destructor Documentation

Constructor, increment instance count. If instance count was zero, register SIGINT handler

Definition at line 82 of file MsqInterrupt.cpp.

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

Constructor, decrement instance count. If instance count goes to zero, remove SIGINT handler

Definition at line 92 of file MsqInterrupt.cpp.

References instanceCount, MBMesquite::oldHandler, and sawInterrupt.

{
    if( !--instanceCount && SIG_ERR != oldHandler )
    {
        signal( SIGINT, oldHandler );
        oldHandler = SIG_ERR;
    }
    sawInterrupt = false;
}

Member Function Documentation

void MBMesquite::MsqInterrupt::allow ( MsqError err) [static]

Allow Mesquite to register a SIGINT handler.

Definition at line 75 of file MsqInterrupt.cpp.

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

{
    sawInterrupt  = false;
    interruptMode = AUTO;
    if( instanceCount && SIG_ERR == oldHandler ) set_handler();
}
static void MBMesquite::MsqInterrupt::clear ( ) [inline, static]

Clear the interrupt flag.

Definition at line 68 of file MsqInterrupt.hpp.

References sawInterrupt.

    {
        sawInterrupt = false;
    }
void MBMesquite::MsqInterrupt::disable ( MsqError err) [static]

Disable Mesquite's SIGINT handler.

Definition at line 57 of file MsqInterrupt.cpp.

References IGNORE, instanceCount, interruptMode, MBMesquite::oldHandler, and sawInterrupt.

{
    interruptMode = IGNORE;
    if( instanceCount && SIG_ERR != oldHandler )
    {
        signal( SIGINT, oldHandler );
        oldHandler = SIG_ERR;
    }
    sawInterrupt = false;
}
void MBMesquite::MsqInterrupt::enable ( MsqError err) [static]

Force Mesquite to register SIGINT handler.

Definition at line 68 of file MsqInterrupt.cpp.

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

{
    sawInterrupt  = false;
    interruptMode = CATCH;
    if( instanceCount && SIG_ERR == oldHandler ) set_handler();
}
static bool MBMesquite::MsqInterrupt::interrupt ( ) [inline, static]

Check if an interrupt was seen.

Definition at line 63 of file MsqInterrupt.hpp.

References sawInterrupt.

Referenced by MBMesquite::InstructionQueue::run_common(), and MBMesquite::TerminationCriterion::terminate().

    {
        return sawInterrupt;
    }
void* MBMesquite::MsqInterrupt::operator new ( size_t  size) [private]
MsqInterrupt& MBMesquite::MsqInterrupt::operator= ( const MsqInterrupt ) [private]

Definition at line 47 of file MsqInterrupt.cpp.

References AUTO, interruptMode, MBMesquite::msq_sigint_handler(), and MBMesquite::oldHandler.

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

{
    oldHandler = signal( SIGINT, &msq_sigint_handler );
    if( MsqInterrupt::interruptMode == MsqInterrupt::AUTO && ( oldHandler == SIG_DFL || oldHandler == SIG_IGN ) )
    {
        signal( SIGINT, oldHandler );
        oldHandler = SIG_ERR;
    }
}
static void MBMesquite::MsqInterrupt::set_interrupt ( ) [inline, static]

Set the interrupt flag.

Definition at line 73 of file MsqInterrupt.hpp.

References sawInterrupt.

Referenced by MBMesquite::msq_sigint_handler().

    {
        sawInterrupt = true;
    }

Member Data Documentation

unsigned MBMesquite::MsqInterrupt::instanceCount = 0 [static, private]

Definition at line 96 of file MsqInterrupt.hpp.

Referenced by allow(), disable(), enable(), MsqInterrupt(), and ~MsqInterrupt().

bool MBMesquite::MsqInterrupt::sawInterrupt = false [static, private]

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines