xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/event-pipe.h (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
14b169a6bSchristos /* Event pipe for GDB, the GNU debugger.
24b169a6bSchristos 
3*5ba1f45fSchristos    Copyright (C) 2021-2024 Free Software Foundation, Inc.
44b169a6bSchristos 
54b169a6bSchristos    This file is part of GDB.
64b169a6bSchristos 
74b169a6bSchristos    This program is free software; you can redistribute it and/or modify
84b169a6bSchristos    it under the terms of the GNU General Public License as published by
94b169a6bSchristos    the Free Software Foundation; either version 3 of the License, or
104b169a6bSchristos    (at your option) any later version.
114b169a6bSchristos 
124b169a6bSchristos    This program is distributed in the hope that it will be useful,
134b169a6bSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
144b169a6bSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154b169a6bSchristos    GNU General Public License for more details.
164b169a6bSchristos 
174b169a6bSchristos    You should have received a copy of the GNU General Public License
184b169a6bSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
194b169a6bSchristos 
204b169a6bSchristos #ifndef COMMON_EVENT_PIPE_H
214b169a6bSchristos #define COMMON_EVENT_PIPE_H
224b169a6bSchristos 
234b169a6bSchristos /* An event pipe used as a waitable file in the event loop in place of
244b169a6bSchristos    some other event associated with a signal.  The handler for the
254b169a6bSchristos    signal marks the event pipe to force a wakeup in the event loop.
264b169a6bSchristos    This uses the well-known self-pipe trick.  */
274b169a6bSchristos 
284b169a6bSchristos class event_pipe
294b169a6bSchristos {
304b169a6bSchristos public:
314b169a6bSchristos   event_pipe() = default;
324b169a6bSchristos   ~event_pipe();
334b169a6bSchristos 
344b169a6bSchristos   DISABLE_COPY_AND_ASSIGN (event_pipe);
354b169a6bSchristos 
364b169a6bSchristos   /* Create a new pipe.  */
374b169a6bSchristos   bool open_pipe ();
384b169a6bSchristos 
394b169a6bSchristos   /* Close the pipe.  */
404b169a6bSchristos   void close_pipe ();
414b169a6bSchristos 
424b169a6bSchristos   /* True if the event pipe has been opened.  */
434b169a6bSchristos   bool is_open () const
444b169a6bSchristos   { return m_fds[0] != -1; }
454b169a6bSchristos 
464b169a6bSchristos   /* The file descriptor of the waitable file to use in the event
474b169a6bSchristos      loop.  */
484b169a6bSchristos   int event_fd () const
494b169a6bSchristos   { return m_fds[0]; }
504b169a6bSchristos 
514b169a6bSchristos   /* Flush the event pipe.  */
524b169a6bSchristos   void flush ();
534b169a6bSchristos 
544b169a6bSchristos   /* Put something in the pipe, so the event loop wakes up.  */
554b169a6bSchristos   void mark ();
564b169a6bSchristos private:
574b169a6bSchristos   int m_fds[2] = { -1, -1 };
584b169a6bSchristos };
594b169a6bSchristos 
604b169a6bSchristos #endif /* COMMON_EVENT_PIPE_H */
61