[gdb] Fix more typos
[binutils-gdb.git] / gdbsupport / scoped_ignore_sigttou.h
bloba3f8361512a03dc570c1e71de0e50f6e5e365b1f
1 /* Support for ignoring SIGTTOU.
3 Copyright (C) 2003-2023 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 SCOPED_IGNORE_SIGTTOU_H
21 #define SCOPED_IGNORE_SIGTTOU_H
23 #include "gdbsupport/scoped_ignore_signal.h"
24 #include "gdbsupport/job-control.h"
26 #ifdef SIGTTOU
28 /* Simple wrapper that allows lazy initialization / destruction of T.
29 Slightly more efficient than gdb::optional, because it doesn't
30 carry storage to track whether the object has been initialized. */
31 template<typename T>
32 class lazy_init
34 public:
35 void emplace ()
37 new (&m_u.obj) T ();
40 void reset ()
42 m_u.obj.~T ();
45 private:
46 union u
48 /* Must define ctor/dtor if T has non-trivial ctor/dtor. */
49 u () {}
50 ~u () {}
52 T obj;
53 } m_u;
56 /* RAII class used to ignore SIGTTOU in a scope. This isn't simply
57 scoped_ignore_signal<SIGTTOU> because we want to check the
58 `job_control' global. */
60 class scoped_ignore_sigttou
62 public:
63 scoped_ignore_sigttou ()
65 if (job_control)
66 m_ignore_signal.emplace ();
69 ~scoped_ignore_sigttou ()
71 if (job_control)
72 m_ignore_signal.reset ();
75 DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou);
77 private:
78 lazy_init<scoped_ignore_signal<SIGTTOU, false>> m_ignore_signal;
81 #else
83 using scoped_ignore_sigttou = scoped_ignore_signal_nop;
85 #endif
87 #endif /* SCOPED_IGNORE_SIGTTOU_H */