μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SigBusGuard.hpp
Go to the documentation of this file.
1/*
2---------------------------------------------------------------------------
3
4 This file is part of uHAL.
5
6 uHAL is a hardware access library and programming framework
7 originally developed for upgrades of the Level-1 trigger of the CMS
8 experiment at CERN.
9
10 uHAL is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 uHAL is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22
23
24 Tom Williams, Rutherford Appleton Laboratory
25 email: tom.williams <AT> cern.ch
26
27 Dan Gastler, Boston University
28 email: dgastler <AT> bu.edu
29
30---------------------------------------------------------------------------
31*/
32
33
34#ifndef _uhal_SigBusGuard_hpp_
35#define _uhal_SigBusGuard_hpp_
36
37
38#include <functional>
39#include <mutex>
40#include <setjmp.h>
41#include <signal.h>
42#include <stdint.h>
43#include <string>
44
47
48
49namespace uhal {
50
51 namespace exception {
52 UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( SigBusError , TransactionLevelError, "Exception caused by a SIGBUS signal." )
53 UHAL_DEFINE_EXCEPTION_CLASS ( SignalHandlerNotRegistered , "Exception associated with signal handler registration errors." )
54 UHAL_DEFINE_EXCEPTION_CLASS ( SignalMaskingFailure , "Exception associated with signal masking errors." )
55 UHAL_DEFINE_EXCEPTION_CLASS ( SignalNotBlocked , "Exception associated with SIGBUS not being masked when using uHAL." )
56 }
57
59 public:
61
63
64 void protect(const std::function<void()>&, const std::string&);
65
66 static void blockSIGBUS();
67
68 private:
69 static void handle(int);
70 std::lock_guard<std::mutex> mLockGuard;
71 struct sigaction mAction;
72 struct sigaction mOriginalAction;
73 sigset_t mOriginalMask;
74
75 static std::mutex sMutex;
76 static sigjmp_buf sEnv;
77 volatile static sig_atomic_t sProtected;
78 };
79
80}
81
82#endif
Wrapper to generate a new Python exception type.
Definition: pybind11.h:2517
\rst Holds a reference to a Python object (no reference counting)
Definition: pytypes.h:194
sigset_t mOriginalMask
Definition: SigBusGuard.hpp:73
static sigjmp_buf sEnv
Definition: SigBusGuard.hpp:76
static volatile sig_atomic_t sProtected
Definition: SigBusGuard.hpp:77
static std::mutex sMutex
Definition: SigBusGuard.hpp:75
std::lock_guard< std::mutex > mLockGuard
Definition: SigBusGuard.hpp:70
#define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, BaseClassName, ClassDescription)
Macro for simplifying the declaration and definition of derived exception types.
Definition: exception.hpp:49
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59