/* Generic serial interface functions.
- Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2003,
- 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 1992-1996, 1998-2001, 2003-2012 Free Software
+ Foundation, Inc.
This file is part of GDB.
}
}
+/* Run the SCB's async handle, and reschedule, if the handler doesn't
+ close SCB. */
+
+static void
+run_async_handler_and_reschedule (struct serial *scb)
+{
+ int is_open;
+
+ /* Take a reference, so a serial_close call within the handler
+ doesn't make SCB a dangling pointer. */
+ serial_ref (scb);
+
+ /* Run the handler. */
+ scb->async_handler (scb, scb->async_context);
+
+ is_open = serial_is_open (scb);
+ serial_unref (scb);
+
+ /* Get ready for more, if not already closed. */
+ if (is_open)
+ reschedule (scb);
+}
+
/* FD_EVENT: This is scheduled when the input FIFO is empty (and there
is no pending error). As soon as data arrives, it is read into the
input FIFO and the client notified. The client should then drain
scb->bufcnt = SERIAL_ERROR;
}
}
- scb->async_handler (scb, scb->async_context);
- reschedule (scb);
+ run_async_handler_and_reschedule (scb);
}
/* PUSH_EVENT: The input FIFO is non-empty (or there is a pending
struct serial *scb = context;
scb->async_state = NOTHING_SCHEDULED; /* Timers are one-off */
- scb->async_handler (scb, scb->async_context);
- /* re-schedule */
- reschedule (scb);
+ run_async_handler_and_reschedule (scb);
}
/* Wait for input on scb, with timeout seconds. Returns 0 on success,