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

File 0001-rtems_termios_puts-Write-more-than-one-char-at-once.patch, 2.6 KB (added by Kolja Waschk, on Aug 7, 2014 at 10:53:54 AM)

Patch for termios.c as described

  • cpukit/libcsupport/src/termios.c

    From 7e8722aeb70aca1982fce4510758ed823e15792f Mon Sep 17 00:00:00 2001
    From: Kolja Waschk <rtemsdev@ixo.de>
    Date: Thu, 7 Aug 2014 13:13:57 +0200
    Subject: [PATCH] rtems_termios_puts: Write more than one char at once
    
    ---
     cpukit/libcsupport/src/termios.c | 34 ++++++++++++++++------------------
     1 file changed, 16 insertions(+), 18 deletions(-)
    
    diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
    index 2448ea1..9fb456d 100644
    a b rtems_termios_puts ( 
    989989    (*tty->handler.write)(tty, buf, len);
    990990    return;
    991991  }
    992   newHead = tty->rawOutBuf.Head;
     992
     993  newHead = (tty->rawOutBuf.Head + 1) % tty->rawOutBuf.Size;
    993994  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;
     995    /* Check space for at least one char */
    1007996    rtems_termios_interrupt_lock_acquire (tty, &lock_context);
    1008997    while (newHead == tty->rawOutBuf.Tail) {
    1009998      tty->rawOutBufState = rob_wait;
    rtems_termios_puts ( 
    10141003        rtems_fatal_error_occurred (sc);
    10151004      rtems_termios_interrupt_lock_acquire (tty, &lock_context);
    10161005    }
    1017     tty->rawOutBuf.theBuf[tty->rawOutBuf.Head] = *buf++;
    1018     tty->rawOutBuf.Head = newHead;
     1006
     1007    /* Copy as much chars as fit until current tail or end of ring buffer */
     1008    int partlen = 0;
     1009    do {
     1010      tty->rawOutBuf.theBuf[tty->rawOutBuf.Head] = *buf++;
     1011      tty->rawOutBuf.Head = newHead;
     1012      newHead = (newHead + 1 ) % tty->rawOutBuf.Size;
     1013      partlen ++;
     1014    }
     1015    while (partlen < len && newHead != tty->rawOutBuf.Tail && tty->rawOutBuf.Head != 0);
     1016
    10191017    if (tty->rawOutBufState == rob_idle) {
    10201018      /* check, whether XOFF has been received */
    10211019      if (!(tty->flow_ctrl & FL_ORCVXOF)) {
    10221020        (*tty->handler.write)(
    1023           tty, &tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail],1);
     1021          tty, &tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail], partlen);
    10241022      } else {
    10251023        /* remember that output has been stopped due to flow ctrl*/
    10261024        tty->flow_ctrl |= FL_OSTOP;
    rtems_termios_puts ( 
    10281026      tty->rawOutBufState = rob_busy;
    10291027    }
    10301028    rtems_termios_interrupt_lock_release (tty, &lock_context);
    1031     len--;
     1029    len -= partlen;
    10321030  }
    10331031}
    10341032