event-pipe.h 1.7 KB

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