sigInt.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2011 Symscape
10 Copyright (C) 2018-2021 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
13 This file is part of OpenFOAM.
14
15 OpenFOAM is free software: you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27
28\*---------------------------------------------------------------------------*/
29
30#include "sigInt.H"
31#include "error.H"
32#include "JobInfo.H"
33#include "IOstreams.H"
34
35// File-local functions
36#include "signalMacros.C"
37
38
39// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40
41bool Foam::sigInt::sigActive_ = false;
42
43
44// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45
46void Foam::sigInt::sigHandler(int)
47{
48 resetHandler("SIGINT", SIGINT);
49
50 JobInfo::shutdown(); // From running -> finished
51 ::raise(SIGINT); // Throw signal (to old handler)
52}
53
54
55// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56
58{
59 set(false);
60}
61
62
63// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64
66{
67 unset(false);
68}
69
70
71// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72
74{
75 if (sigActive_)
76 {
77 return;
78 }
79 sigActive_ = true;
80
81 setHandler("SIGINT", SIGINT, sigHandler);
82}
83
84
85void Foam::sigInt::unset(const bool verbose)
86{
87 if (!sigActive_)
88 {
89 return;
90 }
91 sigActive_ = false;
92
93 resetHandler("SIGINT", SIGINT);
94}
95
96
97// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
File-local code for setting/resetting signal handlers.
static void shutdown()
Simple shutdown (finalize) of JobInfo.
Definition: JobInfo.C:98
~sigInt()
Destructor.
Definition: sigInt.C:65
sigInt()
Construct null.
Definition: sigInt.C:57
static const triad unset
Definition: triad.H:97
bool set() const
Are all the vector set.
Definition: triadI.H:76
static void setHandler(const char *what, int sigNum, void(*handler)(int))
Definition: signalMacros.C:61
static void resetHandler(const char *what, int sigNum)
Definition: signalMacros.C:46