Changeset a75c783 in rtems


Ignore:
Timestamp:
Oct 21, 1997, 5:03:18 PM (23 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
97faafa5
Parents:
55e1322
Message:

Converted from using a message queue for the raw input queue to using a
ring buffer in conjunction with a counting semaphore.

Files:
3 edited

Legend:

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

    r55e1322 ra75c783  
    2424#include <termios.h>
    2525#include <unistd.h>
     26#include <ringbuf.h>
    2627
    2728/*
     
    2930 */
    3031#define CBUFSIZE  256
    31 
    32 /*
    33  * The size of the raw input message queue
    34  */
    35 #define RAW_MESSAGE_QUEUE_COUNT 10
    36 #define RAW_MESSAGE_QUEUE_SIZE  16
    3732
    3833/*
     
    8681   * Raw character buffer
    8782   */
    88   rtems_id  rawInputQueue;
    89   char    rawBuf[RAW_MESSAGE_QUEUE_SIZE];
    90   int   rawBufCount;
    91   int   rawBufIndex;
     83  rtems_id      rawInputSem;
     84  Ring_buffer_t rawInputBuffer;
     85
    9286  rtems_unsigned32  rawMessageOptions;
    9387  rtems_interval  rawMessageTimeout;
     
    9892   */
    9993  int   (*lastClose)(int major, int minor, void *arg);
    100   int   (*read)(int minor, char *buf /*, int len */);
     94  int   (*read)(int minor, char *buf );
    10195  int   (*write)(int minor, char *buf, int len);
    10296};
     
    195189    tty->lastClose = deviceLastClose;
    196190    if ((tty->read = deviceRead) == NULL) {
    197       sc = rtems_message_queue_create (
    198         rtems_build_name ('T', 'R', 'i', c),
    199         RAW_MESSAGE_QUEUE_COUNT,
    200         RAW_MESSAGE_QUEUE_SIZE,
    201         RTEMS_FIFO | RTEMS_LOCAL,
    202         &tty->rawInputQueue);
     191      sc = rtems_semaphore_create (
     192        rtems_build_name ('T', 'R', 'r', c),
     193        0,
     194        RTEMS_COUNTING_SEMAPHORE | RTEMS_FIFO | RTEMS_LOCAL,
     195        RTEMS_NO_PRIORITY,
     196        &tty->rawInputSem);
    203197      if (sc != RTEMS_SUCCESSFUL)
    204198        rtems_fatal_error_occurred (sc);
    205       tty->rawBufCount = tty->rawBufIndex = 0;
    206199    }
    207200
     
    276269    rtems_semaphore_delete (tty->osem);
    277270    if (tty->read == NULL)
    278       rtems_message_queue_delete (tty->rawInputQueue);
     271      rtems_semaphore_delete (tty->rawInputSem);
    279272    free (tty);
    280273  }
     
    669662  rtems_interval timeout = tty->rawMessageFirstTimeout;
    670663  rtems_status_code sc;
    671   rtems_unsigned32 msgSize;
     664  rtems_unsigned8   c;
    672665
    673666  for (;;) {
    674     /*
    675      * Process characters read from raw queue
    676      */
    677     while (tty->rawBufIndex < tty->rawBufCount) {
    678       unsigned char c = tty->rawBuf[tty->rawBufIndex++];
    679       if (tty->termios.c_lflag & ICANON) {
    680         if  (siproc (c, tty))
    681           return RTEMS_SUCCESSFUL;
    682       }
    683       else {
    684         siproc (c, tty);
    685         if (tty->ccount >= tty->termios.c_cc[VMIN])
    686           return RTEMS_SUCCESSFUL;
    687       }
    688     }
    689667
    690668    /*
    691669     * Read characters from raw queue
    692670     */
    693     msgSize = RAW_MESSAGE_QUEUE_SIZE;
    694     sc = rtems_message_queue_receive (tty->rawInputQueue,
    695               tty->rawBuf,
    696               &msgSize,
     671    sc = rtems_semaphore_obtain (tty->rawInputSem,
    697672              tty->rawMessageOptions,
    698673              timeout);
    699674    if (sc != RTEMS_SUCCESSFUL)
    700675      break;
    701     tty->rawBufIndex = 0;
    702     tty->rawBufCount = msgSize;
     676    Ring_buffer_Remove_character( &tty->rawInputBuffer, c );
     677
     678   /*
     679    * Process characters read from raw queue
     680    */
     681    if (tty->termios.c_lflag & ICANON) {
     682      if  (siproc (c, tty))
     683        return RTEMS_SUCCESSFUL;
     684    }
     685    else {
     686      siproc (c, tty);
     687      if (tty->ccount >= tty->termios.c_cc[VMIN])
     688        return RTEMS_SUCCESSFUL;
     689    }
     690
    703691    timeout = tty->rawMessageTimeout;
    704692  }
     
    745733{
    746734  struct rtems_termios_tty *tty = ttyp;
    747   int ncopy;
    748735
    749736  while (len) {
    750     if (len < RAW_MESSAGE_QUEUE_SIZE)
    751       ncopy = len;
    752     else
    753       ncopy = RAW_MESSAGE_QUEUE_SIZE;
    754     if (rtems_message_queue_send (tty->rawInputQueue, buf, ncopy) != RTEMS_SUCCESSFUL)
    755       break;
    756     len -= ncopy;
    757     buf += ncopy;
    758   }
    759 }
    760 
     737    if (Ring_buffer_Is_full(&tty->rawInputBuffer))
     738      break;
     739    Ring_buffer_Add_character(&tty->rawInputBuffer, *buf);
     740    if (rtems_semaphore_release(tty->rawInputSem) != RTEMS_SUCCESSFUL)
     741      break;
     742    len -= 1;
     743    buf += 1;
     744  }
     745}
     746
  • c/src/lib/libc/termios.c

    r55e1322 ra75c783  
    2424#include <termios.h>
    2525#include <unistd.h>
     26#include <ringbuf.h>
    2627
    2728/*
     
    2930 */
    3031#define CBUFSIZE  256
    31 
    32 /*
    33  * The size of the raw input message queue
    34  */
    35 #define RAW_MESSAGE_QUEUE_COUNT 10
    36 #define RAW_MESSAGE_QUEUE_SIZE  16
    3732
    3833/*
     
    8681   * Raw character buffer
    8782   */
    88   rtems_id  rawInputQueue;
    89   char    rawBuf[RAW_MESSAGE_QUEUE_SIZE];
    90   int   rawBufCount;
    91   int   rawBufIndex;
     83  rtems_id      rawInputSem;
     84  Ring_buffer_t rawInputBuffer;
     85
    9286  rtems_unsigned32  rawMessageOptions;
    9387  rtems_interval  rawMessageTimeout;
     
    9892   */
    9993  int   (*lastClose)(int major, int minor, void *arg);
    100   int   (*read)(int minor, char *buf /*, int len */);
     94  int   (*read)(int minor, char *buf );
    10195  int   (*write)(int minor, char *buf, int len);
    10296};
     
    195189    tty->lastClose = deviceLastClose;
    196190    if ((tty->read = deviceRead) == NULL) {
    197       sc = rtems_message_queue_create (
    198         rtems_build_name ('T', 'R', 'i', c),
    199         RAW_MESSAGE_QUEUE_COUNT,
    200         RAW_MESSAGE_QUEUE_SIZE,
    201         RTEMS_FIFO | RTEMS_LOCAL,
    202         &tty->rawInputQueue);
     191      sc = rtems_semaphore_create (
     192        rtems_build_name ('T', 'R', 'r', c),
     193        0,
     194        RTEMS_COUNTING_SEMAPHORE | RTEMS_FIFO | RTEMS_LOCAL,
     195        RTEMS_NO_PRIORITY,
     196        &tty->rawInputSem);
    203197      if (sc != RTEMS_SUCCESSFUL)
    204198        rtems_fatal_error_occurred (sc);
    205       tty->rawBufCount = tty->rawBufIndex = 0;
    206199    }
    207200
     
    276269    rtems_semaphore_delete (tty->osem);
    277270    if (tty->read == NULL)
    278       rtems_message_queue_delete (tty->rawInputQueue);
     271      rtems_semaphore_delete (tty->rawInputSem);
    279272    free (tty);
    280273  }
     
    669662  rtems_interval timeout = tty->rawMessageFirstTimeout;
    670663  rtems_status_code sc;
    671   rtems_unsigned32 msgSize;
     664  rtems_unsigned8   c;
    672665
    673666  for (;;) {
    674     /*
    675      * Process characters read from raw queue
    676      */
    677     while (tty->rawBufIndex < tty->rawBufCount) {
    678       unsigned char c = tty->rawBuf[tty->rawBufIndex++];
    679       if (tty->termios.c_lflag & ICANON) {
    680         if  (siproc (c, tty))
    681           return RTEMS_SUCCESSFUL;
    682       }
    683       else {
    684         siproc (c, tty);
    685         if (tty->ccount >= tty->termios.c_cc[VMIN])
    686           return RTEMS_SUCCESSFUL;
    687       }
    688     }
    689667
    690668    /*
    691669     * Read characters from raw queue
    692670     */
    693     msgSize = RAW_MESSAGE_QUEUE_SIZE;
    694     sc = rtems_message_queue_receive (tty->rawInputQueue,
    695               tty->rawBuf,
    696               &msgSize,
     671    sc = rtems_semaphore_obtain (tty->rawInputSem,
    697672              tty->rawMessageOptions,
    698673              timeout);
    699674    if (sc != RTEMS_SUCCESSFUL)
    700675      break;
    701     tty->rawBufIndex = 0;
    702     tty->rawBufCount = msgSize;
     676    Ring_buffer_Remove_character( &tty->rawInputBuffer, c );
     677
     678   /*
     679    * Process characters read from raw queue
     680    */
     681    if (tty->termios.c_lflag & ICANON) {
     682      if  (siproc (c, tty))
     683        return RTEMS_SUCCESSFUL;
     684    }
     685    else {
     686      siproc (c, tty);
     687      if (tty->ccount >= tty->termios.c_cc[VMIN])
     688        return RTEMS_SUCCESSFUL;
     689    }
     690
    703691    timeout = tty->rawMessageTimeout;
    704692  }
     
    745733{
    746734  struct rtems_termios_tty *tty = ttyp;
    747   int ncopy;
    748735
    749736  while (len) {
    750     if (len < RAW_MESSAGE_QUEUE_SIZE)
    751       ncopy = len;
    752     else
    753       ncopy = RAW_MESSAGE_QUEUE_SIZE;
    754     if (rtems_message_queue_send (tty->rawInputQueue, buf, ncopy) != RTEMS_SUCCESSFUL)
    755       break;
    756     len -= ncopy;
    757     buf += ncopy;
    758   }
    759 }
    760 
     737    if (Ring_buffer_Is_full(&tty->rawInputBuffer))
     738      break;
     739    Ring_buffer_Add_character(&tty->rawInputBuffer, *buf);
     740    if (rtems_semaphore_release(tty->rawInputSem) != RTEMS_SUCCESSFUL)
     741      break;
     742    len -= 1;
     743    buf += 1;
     744  }
     745}
     746
  • cpukit/libcsupport/src/termios.c

    r55e1322 ra75c783  
    2424#include <termios.h>
    2525#include <unistd.h>
     26#include <ringbuf.h>
    2627
    2728/*
     
    2930 */
    3031#define CBUFSIZE  256
    31 
    32 /*
    33  * The size of the raw input message queue
    34  */
    35 #define RAW_MESSAGE_QUEUE_COUNT 10
    36 #define RAW_MESSAGE_QUEUE_SIZE  16
    3732
    3833/*
     
    8681   * Raw character buffer
    8782   */
    88   rtems_id  rawInputQueue;
    89   char    rawBuf[RAW_MESSAGE_QUEUE_SIZE];
    90   int   rawBufCount;
    91   int   rawBufIndex;
     83  rtems_id      rawInputSem;
     84  Ring_buffer_t rawInputBuffer;
     85
    9286  rtems_unsigned32  rawMessageOptions;
    9387  rtems_interval  rawMessageTimeout;
     
    9892   */
    9993  int   (*lastClose)(int major, int minor, void *arg);
    100   int   (*read)(int minor, char *buf /*, int len */);
     94  int   (*read)(int minor, char *buf );
    10195  int   (*write)(int minor, char *buf, int len);
    10296};
     
    195189    tty->lastClose = deviceLastClose;
    196190    if ((tty->read = deviceRead) == NULL) {
    197       sc = rtems_message_queue_create (
    198         rtems_build_name ('T', 'R', 'i', c),
    199         RAW_MESSAGE_QUEUE_COUNT,
    200         RAW_MESSAGE_QUEUE_SIZE,
    201         RTEMS_FIFO | RTEMS_LOCAL,
    202         &tty->rawInputQueue);
     191      sc = rtems_semaphore_create (
     192        rtems_build_name ('T', 'R', 'r', c),
     193        0,
     194        RTEMS_COUNTING_SEMAPHORE | RTEMS_FIFO | RTEMS_LOCAL,
     195        RTEMS_NO_PRIORITY,
     196        &tty->rawInputSem);
    203197      if (sc != RTEMS_SUCCESSFUL)
    204198        rtems_fatal_error_occurred (sc);
    205       tty->rawBufCount = tty->rawBufIndex = 0;
    206199    }
    207200
     
    276269    rtems_semaphore_delete (tty->osem);
    277270    if (tty->read == NULL)
    278       rtems_message_queue_delete (tty->rawInputQueue);
     271      rtems_semaphore_delete (tty->rawInputSem);
    279272    free (tty);
    280273  }
     
    669662  rtems_interval timeout = tty->rawMessageFirstTimeout;
    670663  rtems_status_code sc;
    671   rtems_unsigned32 msgSize;
     664  rtems_unsigned8   c;
    672665
    673666  for (;;) {
    674     /*
    675      * Process characters read from raw queue
    676      */
    677     while (tty->rawBufIndex < tty->rawBufCount) {
    678       unsigned char c = tty->rawBuf[tty->rawBufIndex++];
    679       if (tty->termios.c_lflag & ICANON) {
    680         if  (siproc (c, tty))
    681           return RTEMS_SUCCESSFUL;
    682       }
    683       else {
    684         siproc (c, tty);
    685         if (tty->ccount >= tty->termios.c_cc[VMIN])
    686           return RTEMS_SUCCESSFUL;
    687       }
    688     }
    689667
    690668    /*
    691669     * Read characters from raw queue
    692670     */
    693     msgSize = RAW_MESSAGE_QUEUE_SIZE;
    694     sc = rtems_message_queue_receive (tty->rawInputQueue,
    695               tty->rawBuf,
    696               &msgSize,
     671    sc = rtems_semaphore_obtain (tty->rawInputSem,
    697672              tty->rawMessageOptions,
    698673              timeout);
    699674    if (sc != RTEMS_SUCCESSFUL)
    700675      break;
    701     tty->rawBufIndex = 0;
    702     tty->rawBufCount = msgSize;
     676    Ring_buffer_Remove_character( &tty->rawInputBuffer, c );
     677
     678   /*
     679    * Process characters read from raw queue
     680    */
     681    if (tty->termios.c_lflag & ICANON) {
     682      if  (siproc (c, tty))
     683        return RTEMS_SUCCESSFUL;
     684    }
     685    else {
     686      siproc (c, tty);
     687      if (tty->ccount >= tty->termios.c_cc[VMIN])
     688        return RTEMS_SUCCESSFUL;
     689    }
     690
    703691    timeout = tty->rawMessageTimeout;
    704692  }
     
    745733{
    746734  struct rtems_termios_tty *tty = ttyp;
    747   int ncopy;
    748735
    749736  while (len) {
    750     if (len < RAW_MESSAGE_QUEUE_SIZE)
    751       ncopy = len;
    752     else
    753       ncopy = RAW_MESSAGE_QUEUE_SIZE;
    754     if (rtems_message_queue_send (tty->rawInputQueue, buf, ncopy) != RTEMS_SUCCESSFUL)
    755       break;
    756     len -= ncopy;
    757     buf += ncopy;
    758   }
    759 }
    760 
     737    if (Ring_buffer_Is_full(&tty->rawInputBuffer))
     738      break;
     739    Ring_buffer_Add_character(&tty->rawInputBuffer, *buf);
     740    if (rtems_semaphore_release(tty->rawInputSem) != RTEMS_SUCCESSFUL)
     741      break;
     742    len -= 1;
     743    buf += 1;
     744  }
     745}
     746
Note: See TracChangeset for help on using the changeset viewer.