Automatic date update in version.in
[binutils-gdb.git] / gdbsupport / block-signals.h
blobcf97208c75069303099e4e7f7103b2c442b32f06
1 /* Block signals used by gdb
3 Copyright (C) 2019-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GDBSUPPORT_BLOCK_SIGNALS_H
21 #define GDBSUPPORT_BLOCK_SIGNALS_H
23 #include <signal.h>
25 #include "gdbsupport/gdb-sigmask.h"
27 namespace gdb
30 /* This is an RAII class that temporarily blocks the signals needed by
31 gdb. This can be used before starting a new thread to ensure that
32 this thread starts with the appropriate signals blocked. */
33 class block_signals
35 public:
36 block_signals ()
38 #ifdef HAVE_SIGPROCMASK
39 sigset_t mask;
40 sigemptyset (&mask);
41 sigaddset (&mask, SIGINT);
42 sigaddset (&mask, SIGCHLD);
43 sigaddset (&mask, SIGALRM);
44 sigaddset (&mask, SIGWINCH);
45 gdb_sigmask (SIG_BLOCK, &mask, &m_old_mask);
46 #endif
49 ~block_signals ()
51 #ifdef HAVE_SIGPROCMASK
52 gdb_sigmask (SIG_SETMASK, &m_old_mask, nullptr);
53 #endif
56 DISABLE_COPY_AND_ASSIGN (block_signals);
58 private:
60 #ifdef HAVE_SIGPROCMASK
61 sigset_t m_old_mask;
62 #endif
67 #endif /* GDBSUPPORT_BLOCK_SIGNALS_H */