Ticket #2185: 0001-rtems_termios_puts-Write-more-than-one-char-at-once_v1.patch

File 0001-rtems_termios_puts-Write-more-than-one-char-at-once_v1.patch, 2.9 KB (added by Kolja Waschk, on Aug 7, 2014 at 1:15:18 PM)

Revised patch

  • cpukit/libcsupport/src/termios.c

    From 4652a1c910af67955bd1082e14ead029c0cde355 Mon Sep 17 00:00:00 2001
    From: Kolja Waschk <rtemsdev@ixo.de>
    Date: Thu, 7 Aug 2014 15:56:02 +0200
    Subject: [PATCH] rtems_termios_puts: Write more than one char at once
    
    ---
     cpukit/libcsupport/src/termios.c | 40 ++++++++++++++++++++++------------------
     1 file changed, 22 insertions(+), 18 deletions(-)
    
    diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
    index 2448ea1..14500b1 100644
    a b rtems_termios_puts ( 
    984984  unsigned int newHead;
    985985  rtems_interrupt_lock_context lock_context;
    986986  rtems_status_code sc;
     987  size_t partlen;
    987988
    988989  if (tty->handler.mode == TERMIOS_POLLED) {
    989990    (*tty->handler.write)(tty, buf, len);
    990991    return;
    991992  }
    992   newHead = tty->rawOutBuf.Head;
     993
     994  newHead = tty->rawOutBuf.Head + 1;
     995  if (newHead >= tty->rawOutBuf.Size)
     996    newHead -= tty->rawOutBuf.Size;
     997
    993998  while (len) {
    994     /*
    995      * Performance improvement could be made here.
    996      * Copy multiple bytes to raw buffer:
    997      * if (len > 1) && (space to buffer end, or tail > 1)
    998      *  ncopy = MIN (len, space to buffer end or tail)
    999      *  memcpy (raw buffer, buf, ncopy)
    1000      *  buf += ncopy
    1001      *  len -= ncopy
    1002      *
    1003      * To minimize latency, the memcpy should be done
    1004      * with interrupts enabled.
    1005      */
    1006     newHead = (newHead + 1) % tty->rawOutBuf.Size;
     999    /* Check space for at least one char */
    10071000    rtems_termios_interrupt_lock_acquire (tty, &lock_context);
    10081001    while (newHead == tty->rawOutBuf.Tail) {
    10091002      tty->rawOutBufState = rob_wait;
    rtems_termios_puts ( 
    10141007        rtems_fatal_error_occurred (sc);
    10151008      rtems_termios_interrupt_lock_acquire (tty, &lock_context);
    10161009    }
    1017     tty->rawOutBuf.theBuf[tty->rawOutBuf.Head] = *buf++;
    1018     tty->rawOutBuf.Head = newHead;
     1010
     1011    /* Copy as much chars as fit until current tail or end of ring buffer */
     1012    partlen = 0;
     1013    do {
     1014      tty->rawOutBuf.theBuf[tty->rawOutBuf.Head] = *buf++;
     1015      tty->rawOutBuf.Head = newHead;
     1016      newHead++;
     1017      if (newHead >= tty->rawOutBuf.Size)
     1018        newHead -= tty->rawOutBuf.Size;
     1019      partlen++;
     1020    }
     1021    while (partlen < len && newHead != tty->rawOutBuf.Tail && tty->rawOutBuf.Head != 0);
     1022
    10191023    if (tty->rawOutBufState == rob_idle) {
    10201024      /* check, whether XOFF has been received */
    10211025      if (!(tty->flow_ctrl & FL_ORCVXOF)) {
    10221026        (*tty->handler.write)(
    1023           tty, &tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail],1);
     1027          tty, &tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail], partlen);
    10241028      } else {
    10251029        /* remember that output has been stopped due to flow ctrl*/
    10261030        tty->flow_ctrl |= FL_OSTOP;
    rtems_termios_puts ( 
    10281032      tty->rawOutBufState = rob_busy;
    10291033    }
    10301034    rtems_termios_interrupt_lock_release (tty, &lock_context);
    1031     len--;
     1035    len -= partlen;
    10321036  }
    10331037}
    10341038