summaryrefslogtreecommitdiff
path: root/gdb/serial.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2012-06-11 20:36:53 +0000
committerPedro Alves <palves@redhat.com>2012-06-11 20:36:53 +0000
commit891661e8e5978859393b3c0518d256ccea9ef41d (patch)
tree175915f3e2f821feafd7e8ce32917e0afb2dbf91 /gdb/serial.c
parent877dce5b0d75d33cf93a4cda88a73cf828be5875 (diff)
downloadgdb-891661e8e5978859393b3c0518d256ccea9ef41d.tar.gz
2012-06-11 Pedro Alves <palves@redhat.com>
* ser-base.c (run_async_handler_and_reschedule): New. (fd_event, push_event): Use it. * serial.c (serial_open, serial_fdopen_ops): Set the initial reference count to 1. (do_serial_close): Set the bufp field to NULL. Use serial_unref instead of xfree. (serial_is_open, serial_ref, serial_unref): New. * serial.h (serial_open): Adjust comment. (serial_is_open): Declare. (serial_close): Adjust comment. (serial_ref, serial_unref) Declare. (struct serial): New field 'refcnt'.
Diffstat (limited to 'gdb/serial.c')
-rw-r--r--gdb/serial.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/gdb/serial.c b/gdb/serial.c
index c1f331d7699..1140feb93c5 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -196,6 +196,7 @@ serial_open (const char *name)
scb->bufcnt = 0;
scb->bufp = scb->buf;
scb->error_fd = -1;
+ scb->refcnt = 1;
/* `...->open (...)' would get expanded by the open(2) syscall macro. */
if ((*scb->ops->open) (scb, open_name))
@@ -245,6 +246,7 @@ serial_fdopen_ops (const int fd, struct serial_ops *ops)
scb->bufcnt = 0;
scb->bufp = scb->buf;
scb->error_fd = -1;
+ scb->refcnt = 1;
scb->name = NULL;
scb->debug_p = 0;
@@ -291,7 +293,10 @@ do_serial_close (struct serial *scb, int really_close)
if (scb->name)
xfree (scb->name);
- xfree (scb);
+ /* For serial_is_open. */
+ scb->bufp = NULL;
+
+ serial_unref (scb);
}
void
@@ -307,6 +312,26 @@ serial_un_fdopen (struct serial *scb)
}
int
+serial_is_open (struct serial *scb)
+{
+ return scb->bufp != NULL;
+}
+
+void
+serial_ref (struct serial *scb)
+{
+ scb->refcnt++;
+}
+
+void
+serial_unref (struct serial *scb)
+{
+ --scb->refcnt;
+ if (scb->refcnt == 0)
+ xfree (scb);
+}
+
+int
serial_readchar (struct serial *scb, int timeout)
{
int ch;