Home | History | Annotate | Line # | Download | only in gdb
      1 /* Serial interface for a selectable event.
      2    Copyright (C) 2016-2024 Free Software Foundation, Inc.
      3 
      4    This file is part of GDB.
      5 
      6    This program is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3 of the License, or
      9    (at your option) any later version.
     10 
     11    This program is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     18 
     19 #ifndef SER_EVENT_H
     20 #define SER_EVENT_H
     21 
     22 /* This is used to be able to signal the event loop (or any other
     23    select/poll) of events, in a race-free manner.
     24 
     25    For example, a signal handler can defer non-async-signal-safe work
     26    to the event loop, by having the signal handler set a struct
     27    serial_event object, and having the event loop wait for that same
     28    object to the readable.  Once readable, the event loop breaks out
     29    of select/poll and calls a registered callback that does the
     30    deferred work.  */
     31 
     32 struct serial_event;
     33 
     34 /* Make a new serial_event object.  */
     35 struct serial_event *make_serial_event (void);
     36 
     37 /* Return the FD that can be used by select/poll to wait for the
     38    event.  The only valid operation on this object is to wait until it
     39    is readable.  */
     40 extern int serial_event_fd (struct serial_event *event);
     41 
     42 /* Set the event.  This signals the file descriptor returned by
     43    serial_event_fd as readable.  */
     44 extern void serial_event_set (struct serial_event *event);
     45 
     46 /* Clear the event.  The file descriptor returned by serial_event_fd
     47    is not longer readable after this, until a new serial_event_set
     48    call is made.  */
     49 extern void serial_event_clear (struct serial_event *event);
     50 
     51 #endif
     52