1 1.1 christos /* Event pipe for GDB, the GNU debugger. 2 1.1 christos 3 1.1.1.4 christos Copyright (C) 2021-2025 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.1.1.3 christos #ifndef GDBSUPPORT_EVENT_PIPE_H 21 1.1.1.3 christos #define GDBSUPPORT_EVENT_PIPE_H 22 1.1 christos 23 1.1 christos /* An event pipe used as a waitable file in the event loop in place of 24 1.1 christos some other event associated with a signal. The handler for the 25 1.1 christos signal marks the event pipe to force a wakeup in the event loop. 26 1.1 christos This uses the well-known self-pipe trick. */ 27 1.1 christos 28 1.1 christos class event_pipe 29 1.1 christos { 30 1.1 christos public: 31 1.1 christos event_pipe() = default; 32 1.1 christos ~event_pipe(); 33 1.1 christos 34 1.1 christos DISABLE_COPY_AND_ASSIGN (event_pipe); 35 1.1 christos 36 1.1 christos /* Create a new pipe. */ 37 1.1 christos bool open_pipe (); 38 1.1 christos 39 1.1 christos /* Close the pipe. */ 40 1.1 christos void close_pipe (); 41 1.1 christos 42 1.1 christos /* True if the event pipe has been opened. */ 43 1.1 christos bool is_open () const 44 1.1 christos { return m_fds[0] != -1; } 45 1.1 christos 46 1.1 christos /* The file descriptor of the waitable file to use in the event 47 1.1 christos loop. */ 48 1.1 christos int event_fd () const 49 1.1 christos { return m_fds[0]; } 50 1.1 christos 51 1.1 christos /* Flush the event pipe. */ 52 1.1 christos void flush (); 53 1.1 christos 54 1.1 christos /* Put something in the pipe, so the event loop wakes up. */ 55 1.1 christos void mark (); 56 1.1 christos private: 57 1.1 christos int m_fds[2] = { -1, -1 }; 58 1.1 christos }; 59 1.1 christos 60 1.1.1.3 christos #endif /* GDBSUPPORT_EVENT_PIPE_H */ 61