x86: limit use of XOP2SOURCES
[binutils-gdb.git] / gdbsupport / eintr.h
blobf78d0ec4a2f2358598bdb26da25ee4b53eb4744a
1 /* Utility for handling interrupted syscalls by signals.
3 Copyright (C) 2020-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 GDBSUPPORT_EINTR_H
21 #define GDBSUPPORT_EINTR_H
23 #include <cerrno>
25 namespace gdb
27 /* Repeat a system call interrupted with a signal.
29 A utility for handling interrupted syscalls, which return with error
30 and set the errno to EINTR. The interrupted syscalls can be repeated,
31 until successful completion. This utility avoids wrapping code with
32 manual checks for such errors which are highly repetitive.
34 For example, with:
36 ssize_t ret;
39 errno = 0;
40 ret = ::write (pipe[1], "+", 1);
42 while (ret == -1 && errno == EINTR);
44 You could wrap it by writing the wrapped form:
46 ssize_t ret = gdb::handle_eintr (-1, ::write, pipe[1], "+", 1);
48 ERRVAL specifies the failure value indicating that the call to the
49 F function with ARGS... arguments was possibly interrupted with a
50 signal. */
52 template<typename ErrorValType, typename Fun, typename... Args>
53 inline auto
54 handle_eintr (ErrorValType errval, const Fun &f, const Args &... args)
55 -> decltype (f (args...))
57 decltype (f (args...)) ret;
61 errno = 0;
62 ret = f (args...);
64 while (ret == errval && errno == EINTR);
66 return ret;
69 } /* namespace gdb */
71 #endif /* GDBSUPPORT_EINTR_H */