Changeset 0e8d2055 in rtems


Ignore:
Timestamp:
02/23/17 09:06:52 (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11
Children:
a27128c5
Parents:
35a3d815
git-author:
Sebastian Huber <sebastian.huber@…> (02/23/17 09:06:52)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/28/17 08:55:55)
Message:

termios: Protect raw input buffer with device lock

Use the device lock to protect the raw input buffer management, e.g.
tail, head and buffer content updates.

Update #2914.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/termios.c

    r35a3d815 r0e8d2055  
    14581458fillBufferQueue (struct rtems_termios_tty *tty)
    14591459{
     1460  rtems_termios_device_context *ctx = tty->device_context;
    14601461  rtems_interval timeout = tty->rawInBufSemaphoreFirstTimeout;
    1461   rtems_status_code sc;
    1462   int               wait = 1;
     1462  bool wait = true;
    14631463
    14641464  while ( wait ) {
     1465    rtems_interrupt_lock_context lock_context;
     1466
    14651467    /*
    14661468     * Process characters read from raw queue
    14671469     */
     1470
     1471    rtems_termios_device_lock_acquire (ctx, &lock_context);
     1472
    14681473    while ((tty->rawInBuf.Head != tty->rawInBuf.Tail) &&
    14691474                       (tty->ccount < (CBUFSIZE-1))) {
     
    14741479      c = tty->rawInBuf.theBuf[newHead];
    14751480      tty->rawInBuf.Head = newHead;
     1481
    14761482      if(((tty->rawInBuf.Tail-newHead+tty->rawInBuf.Size)
    14771483          % tty->rawInBuf.Size)
     
    14951501      }
    14961502
     1503      rtems_termios_device_lock_release (ctx, &lock_context);
     1504
    14971505      /* continue processing new character */
    14981506      if (tty->termios.c_lflag & ICANON) {
    14991507        if (siproc (c, tty))
    1500           wait = 0;
     1508          wait = false;
    15011509      } else {
    15021510        siproc (c, tty);
    15031511        if (tty->ccount >= tty->termios.c_cc[VMIN])
    1504           wait = 0;
     1512          wait = false;
    15051513      }
    15061514      timeout = tty->rawInBufSemaphoreTimeout;
    1507     }
     1515
     1516      rtems_termios_device_lock_acquire (ctx, &lock_context);
     1517    }
     1518
     1519    rtems_termios_device_lock_release (ctx, &lock_context);
    15081520
    15091521    /*
     
    15111523     */
    15121524    if ( wait ) {
     1525      rtems_status_code sc;
     1526
    15131527      sc = rtems_semaphore_obtain(
    15141528        tty->rawInBuf.Semaphore, tty->rawInBufSemaphoreOptions, timeout);
     
    15801594{
    15811595  struct rtems_termios_tty *tty = ttyp;
    1582   unsigned int newTail;
    15831596  char c;
    15841597  int dropped = 0;
     
    16451658      }
    16461659    } else {
    1647       newTail = (tty->rawInBuf.Tail + 1) % tty->rawInBuf.Size;
     1660      unsigned int head;
     1661      unsigned int oldTail;
     1662      unsigned int newTail;
     1663
     1664      rtems_termios_device_lock_acquire (ctx, &lock_context);
     1665
     1666      head = tty->rawInBuf.Head;
     1667      oldTail = tty->rawInBuf.Tail;
     1668      newTail = (oldTail + 1) % tty->rawInBuf.Size;
     1669
    16481670      /* if chars_in_buffer > highwater                */
    1649       rtems_termios_device_lock_acquire (ctx, &lock_context);
    1650       if ((((newTail - tty->rawInBuf.Head + tty->rawInBuf.Size)
    1651             % tty->rawInBuf.Size) > tty->highwater) &&
    1652           !(tty->flow_ctrl & FL_IREQXOF)) {
     1671      if ((tty->flow_ctrl & FL_IREQXOF) != 0 && (((newTail - head
     1672          + tty->rawInBuf.Size) % tty->rawInBuf.Size) > tty->highwater)) {
    16531673        /* incoming data stream should be stopped */
    16541674        tty->flow_ctrl |= FL_IREQXOF;
     
    16721692      }
    16731693
    1674       /* reenable interrupts */
    1675       rtems_termios_device_lock_release (ctx, &lock_context);
    1676 
    1677       if (newTail == tty->rawInBuf.Head) {
    1678         dropped++;
    1679       } else {
     1694      if (newTail != head) {
    16801695        tty->rawInBuf.theBuf[newTail] = c;
    16811696        tty->rawInBuf.Tail = newTail;
     1697
     1698        rtems_termios_device_lock_release (ctx, &lock_context);
    16821699
    16831700        /*
     
    16881705          tty->tty_rcvwakeup = 1;
    16891706        }
     1707      } else {
     1708        ++dropped;
     1709        rtems_termios_device_lock_release (ctx, &lock_context);
    16901710      }
    16911711    }
Note: See TracChangeset for help on using the changeset viewer.