| OLD | NEW |
| 1 /* Generic serial interface functions. | 1 /* Generic serial interface functions. |
| 2 | 2 |
| 3 Copyright (C) 1992-1996, 1998-2001, 2003-2012 Free Software | 3 Copyright (C) 1992-1996, 1998-2001, 2003-2012 Free Software |
| 4 Foundation, Inc. | 4 Foundation, Inc. |
| 5 | 5 |
| 6 This file is part of GDB. | 6 This file is part of GDB. |
| 7 | 7 |
| 8 This program is free software; you can redistribute it and/or modify | 8 This program is free software; you can redistribute it and/or modify |
| 9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
| 10 the Free Software Foundation; either version 3 of the License, or | 10 the Free Software Foundation; either version 3 of the License, or |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (scb->async_state == FD_SCHEDULED) | 116 if (scb->async_state == FD_SCHEDULED) |
| 117 fprintf_unfiltered (gdb_stdlog, "[fd%d->timer-scheduled]\n", | 117 fprintf_unfiltered (gdb_stdlog, "[fd%d->timer-scheduled]\n", |
| 118 scb->fd); | 118 scb->fd); |
| 119 break; | 119 break; |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 scb->async_state = next_state; | 122 scb->async_state = next_state; |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 /* Run the SCB's async handle, and reschedule, if the handler doesn't |
| 127 close SCB. */ |
| 128 |
| 129 static void |
| 130 run_async_handler_and_reschedule (struct serial *scb) |
| 131 { |
| 132 int is_open; |
| 133 |
| 134 /* Take a reference, so a serial_close call within the handler |
| 135 doesn't make SCB a dangling pointer. */ |
| 136 serial_ref (scb); |
| 137 |
| 138 /* Run the handler. */ |
| 139 scb->async_handler (scb, scb->async_context); |
| 140 |
| 141 is_open = serial_is_open (scb); |
| 142 serial_unref (scb); |
| 143 |
| 144 /* Get ready for more, if not already closed. */ |
| 145 if (is_open) |
| 146 reschedule (scb); |
| 147 } |
| 148 |
| 126 /* FD_EVENT: This is scheduled when the input FIFO is empty (and there | 149 /* FD_EVENT: This is scheduled when the input FIFO is empty (and there |
| 127 is no pending error). As soon as data arrives, it is read into the | 150 is no pending error). As soon as data arrives, it is read into the |
| 128 input FIFO and the client notified. The client should then drain | 151 input FIFO and the client notified. The client should then drain |
| 129 the FIFO using readchar(). If the FIFO isn't immediatly emptied, | 152 the FIFO using readchar(). If the FIFO isn't immediatly emptied, |
| 130 push_event() is used to nag the client until it is. */ | 153 push_event() is used to nag the client until it is. */ |
| 131 | 154 |
| 132 static void | 155 static void |
| 133 fd_event (int error, void *context) | 156 fd_event (int error, void *context) |
| 134 { | 157 { |
| 135 struct serial *scb = context; | 158 struct serial *scb = context; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 151 else if (nr > 0) | 174 else if (nr > 0) |
| 152 { | 175 { |
| 153 scb->bufcnt = nr; | 176 scb->bufcnt = nr; |
| 154 scb->bufp = scb->buf; | 177 scb->bufp = scb->buf; |
| 155 } | 178 } |
| 156 else | 179 else |
| 157 { | 180 { |
| 158 scb->bufcnt = SERIAL_ERROR; | 181 scb->bufcnt = SERIAL_ERROR; |
| 159 } | 182 } |
| 160 } | 183 } |
| 161 scb->async_handler (scb, scb->async_context); | 184 run_async_handler_and_reschedule (scb); |
| 162 reschedule (scb); | |
| 163 } | 185 } |
| 164 | 186 |
| 165 /* PUSH_EVENT: The input FIFO is non-empty (or there is a pending | 187 /* PUSH_EVENT: The input FIFO is non-empty (or there is a pending |
| 166 error). Nag the client until all the data has been read. In the | 188 error). Nag the client until all the data has been read. In the |
| 167 case of errors, the client will need to close or de-async the | 189 case of errors, the client will need to close or de-async the |
| 168 device before naging stops. */ | 190 device before naging stops. */ |
| 169 | 191 |
| 170 static void | 192 static void |
| 171 push_event (void *context) | 193 push_event (void *context) |
| 172 { | 194 { |
| 173 struct serial *scb = context; | 195 struct serial *scb = context; |
| 174 | 196 |
| 175 scb->async_state = NOTHING_SCHEDULED; /* Timers are one-off */ | 197 scb->async_state = NOTHING_SCHEDULED; /* Timers are one-off */ |
| 176 scb->async_handler (scb, scb->async_context); | 198 run_async_handler_and_reschedule (scb); |
| 177 /* re-schedule */ | |
| 178 reschedule (scb); | |
| 179 } | 199 } |
| 180 | 200 |
| 181 /* Wait for input on scb, with timeout seconds. Returns 0 on success, | 201 /* Wait for input on scb, with timeout seconds. Returns 0 on success, |
| 182 otherwise SERIAL_TIMEOUT or SERIAL_ERROR. */ | 202 otherwise SERIAL_TIMEOUT or SERIAL_ERROR. */ |
| 183 | 203 |
| 184 static int | 204 static int |
| 185 ser_base_wait_for (struct serial *scb, int timeout) | 205 ser_base_wait_for (struct serial *scb, int timeout) |
| 186 { | 206 { |
| 187 while (1) | 207 while (1) |
| 188 { | 208 { |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 delete_file_handler (scb->fd); | 551 delete_file_handler (scb->fd); |
| 532 break; | 552 break; |
| 533 case NOTHING_SCHEDULED: | 553 case NOTHING_SCHEDULED: |
| 534 break; | 554 break; |
| 535 default: /* TIMER SCHEDULED */ | 555 default: /* TIMER SCHEDULED */ |
| 536 delete_timer (scb->async_state); | 556 delete_timer (scb->async_state); |
| 537 break; | 557 break; |
| 538 } | 558 } |
| 539 } | 559 } |
| 540 } | 560 } |
| OLD | NEW |