From 2c12262f9a8fe7975556729f0574fab8d5a792f5 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 28 Nov 2017 06:30:35 +0100 Subject: termios: Use self-contained objects Update #2840. --- cpukit/include/rtems/confdefs.h | 29 +--- cpukit/include/rtems/libio.h | 5 +- cpukit/include/rtems/termiostypes.h | 13 +- cpukit/libcsupport/src/termios.c | 226 +++++++++------------------- cpukit/libcsupport/src/termiosinitialize.c | 32 +--- testsuites/libtests/termios01/init.c | 7 +- testsuites/sptests/Makefile.am | 2 +- testsuites/sptests/configure.ac | 4 - testsuites/sptests/spfatal17/Makefile.am | 24 --- testsuites/sptests/spfatal17/spfatal17.doc | 19 --- testsuites/sptests/spfatal17/spfatal17.scn | 3 - testsuites/sptests/spfatal17/testcase.h | 27 ---- testsuites/sptests/spfatal18/Makefile.am | 24 --- testsuites/sptests/spfatal18/spfatal18.doc | 19 --- testsuites/sptests/spfatal18/spfatal18.scn | 3 - testsuites/sptests/spfatal18/testcase.h | 27 ---- testsuites/sptests/spfatal19/Makefile.am | 24 --- testsuites/sptests/spfatal19/spfatal19.doc | 19 --- testsuites/sptests/spfatal19/spfatal19.scn | 3 - testsuites/sptests/spfatal19/testcase.h | 27 ---- testsuites/sptests/spfatal20/Makefile.am | 24 --- testsuites/sptests/spfatal20/spfatal20.doc | 19 --- testsuites/sptests/spfatal20/spfatal20.scn | 3 - testsuites/sptests/spfatal20/testcase.h | 24 --- testsuites/sptests/spfatal_support/system.h | 4 - 25 files changed, 98 insertions(+), 513 deletions(-) delete mode 100644 testsuites/sptests/spfatal17/Makefile.am delete mode 100644 testsuites/sptests/spfatal17/spfatal17.doc delete mode 100644 testsuites/sptests/spfatal17/spfatal17.scn delete mode 100644 testsuites/sptests/spfatal17/testcase.h delete mode 100644 testsuites/sptests/spfatal18/Makefile.am delete mode 100644 testsuites/sptests/spfatal18/spfatal18.doc delete mode 100644 testsuites/sptests/spfatal18/spfatal18.scn delete mode 100644 testsuites/sptests/spfatal18/testcase.h delete mode 100644 testsuites/sptests/spfatal19/Makefile.am delete mode 100644 testsuites/sptests/spfatal19/spfatal19.doc delete mode 100644 testsuites/sptests/spfatal19/spfatal19.scn delete mode 100644 testsuites/sptests/spfatal19/testcase.h delete mode 100644 testsuites/sptests/spfatal20/Makefile.am delete mode 100644 testsuites/sptests/spfatal20/spfatal20.doc delete mode 100644 testsuites/sptests/spfatal20/spfatal20.scn delete mode 100644 testsuites/sptests/spfatal20/testcase.h diff --git a/cpukit/include/rtems/confdefs.h b/cpukit/include/rtems/confdefs.h index 2169213c25..022026b327 100755 --- a/cpukit/include/rtems/confdefs.h +++ b/cpukit/include/rtems/confdefs.h @@ -155,30 +155,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; const uint32_t rtems_libio_number_iops = RTEMS_ARRAY_SIZE(rtems_libio_iops); #endif -/* - * This macro determines if termios is disabled by this application. - * This only means that resources will not be reserved. If you end - * up using termios, it will fail. - */ -#ifdef CONFIGURE_TERMIOS_DISABLED - #define _CONFIGURE_TERMIOS_SEMAPHORES 0 -#else - /** - * This macro specifies the number of serial or PTY ports that will - * use termios. - */ - #ifndef CONFIGURE_NUMBER_OF_TERMIOS_PORTS - #define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 1 - #endif - - /* - * This macro reserves the number of semaphores required by termios - * based upon the number of communication ports that will use it. - */ - #define _CONFIGURE_TERMIOS_SEMAPHORES \ - ((CONFIGURE_NUMBER_OF_TERMIOS_PORTS * 4) + 1) -#endif - /** * This macro specifies the number of PTYs that can be concurrently * active. @@ -2096,7 +2072,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; */ #define _CONFIGURE_SEMAPHORES \ (CONFIGURE_MAXIMUM_SEMAPHORES + \ - _CONFIGURE_TERMIOS_SEMAPHORES + \ _CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS + \ _CONFIGURE_NETWORKING_SEMAPHORES) @@ -3511,6 +3486,10 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; #error "Maximum priority configured higher than supported by target." #endif +#ifdef CONFIGURE_TERMIOS_DISABLED + #warning "The CONFIGURE_TERMIOS_DISABLED configuration option is obsolete since RTEMS 5.1" +#endif + #ifdef CONFIGURE_MAXIMUM_POSIX_BARRIERS #warning "The CONFIGURE_MAXIMUM_POSIX_BARRIERS configuration option is obsolete since RTEMS 5.1" #endif diff --git a/cpukit/include/rtems/libio.h b/cpukit/include/rtems/libio.h index 9d30dafddf..f3b0f2cbf9 100644 --- a/cpukit/include/rtems/libio.h +++ b/cpukit/include/rtems/libio.h @@ -1891,7 +1891,10 @@ typedef struct rtems_termios_callbacks { int outputUsesInterrupts; } rtems_termios_callbacks; -void rtems_termios_initialize (void); +RTEMS_INLINE_ROUTINE void rtems_termios_initialize( void ) +{ + /* Nothing to do, provided for backward compatibility */ +} /* * CCJ: Change before opening a tty. Newer code from Eric is coming diff --git a/cpukit/include/rtems/termiostypes.h b/cpukit/include/rtems/termiostypes.h index b3cac66e92..db88cada8b 100644 --- a/cpukit/include/rtems/termiostypes.h +++ b/cpukit/include/rtems/termiostypes.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ struct rtems_termios_rawbuf { volatile unsigned int Head; volatile unsigned int Tail; volatile unsigned int Size; - rtems_id Semaphore; + rtems_binary_semaphore Semaphore; }; typedef enum { @@ -77,7 +78,7 @@ typedef struct rtems_termios_device_context { rtems_interrupt_lock interrupt; /* Used for TERMIOS_IRQ_SERVER_DRIVEN or TERMIOS_TASK_DRIVEN */ - rtems_id mutex; + rtems_mutex mutex; } lock; void ( *lock_acquire )( @@ -300,8 +301,8 @@ typedef struct rtems_termios_tty { /* * Mutual-exclusion semaphores */ - rtems_id isem; - rtems_id osem; + rtems_mutex isem; + rtems_mutex osem; /* * The canonical (cooked) character buffer @@ -326,7 +327,7 @@ typedef struct rtems_termios_tty { * Raw input character buffer */ struct rtems_termios_rawbuf rawInBuf; - uint32_t rawInBufSemaphoreOptions; + bool rawInBufSemaphoreWait; rtems_interval rawInBufSemaphoreTimeout; rtems_interval rawInBufSemaphoreFirstTimeout; unsigned int rawInBufDropped; /* Statistics */ @@ -595,6 +596,8 @@ int rtems_termios_poll( #define RTEMS_TERMIOS_NUMBER_BAUD_RATES 25 +extern rtems_mutex rtems_termios_ttyMutex; + #ifdef __cplusplus } #endif diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c index 8303e9f18d..0389ec37b2 100644 --- a/cpukit/libcsupport/src/termios.c +++ b/cpukit/libcsupport/src/termios.c @@ -84,8 +84,6 @@ struct rtems_termios_linesw rtems_termios_linesw[MAXLDISC] = int rtems_termios_nlinesw = sizeof (rtems_termios_linesw) / sizeof (rtems_termios_linesw[0]); -extern rtems_id rtems_termios_ttyMutex; - static size_t rtems_termios_cbufsize = 256; static size_t rtems_termios_raw_input_size = 256; static size_t rtems_termios_raw_output_size = 64; @@ -115,21 +113,16 @@ static rtems_task rtems_termios_txdaemon(rtems_task_argument argument); #define TERMIOS_RX_PROC_EVENT RTEMS_EVENT_1 #define TERMIOS_RX_TERMINATE_EVENT RTEMS_EVENT_0 -static rtems_status_code +static void rtems_termios_obtain (void) { - return rtems_semaphore_obtain (rtems_termios_ttyMutex, RTEMS_WAIT, - RTEMS_NO_TIMEOUT); + rtems_mutex_lock (&rtems_termios_ttyMutex); } static void rtems_termios_release (void) { - rtems_status_code sc; - - sc = rtems_semaphore_release (rtems_termios_ttyMutex); - _Assert (sc == RTEMS_SUCCESSFUL); - (void) sc; + rtems_mutex_unlock (&rtems_termios_ttyMutex); } rtems_status_code rtems_termios_device_install( @@ -258,17 +251,13 @@ drainOutput (struct rtems_termios_tty *tty) { rtems_termios_device_context *ctx = tty->device_context; rtems_interrupt_lock_context lock_context; - rtems_status_code sc; if (tty->handler.mode != TERMIOS_POLLED) { rtems_termios_device_lock_acquire (ctx, &lock_context); while (tty->rawOutBuf.Tail != tty->rawOutBuf.Head) { tty->rawOutBufState = rob_wait; rtems_termios_device_lock_release (ctx, &lock_context); - sc = rtems_semaphore_obtain( - tty->rawOutBuf.Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + rtems_binary_semaphore_wait (&tty->rawOutBuf.Semaphore); rtems_termios_device_lock_acquire (ctx, &lock_context); } rtems_termios_device_lock_release (ctx, &lock_context); @@ -285,8 +274,6 @@ needDeviceMutex (rtems_termios_tty *tty) static void rtems_termios_destroy_tty (rtems_termios_tty *tty, void *arg, bool last_close) { - rtems_status_code sc; - if (rtems_termios_linesw[tty->t_line].l_close != NULL) { /* * call discipline-specific close @@ -296,15 +283,14 @@ rtems_termios_destroy_tty (rtems_termios_tty *tty, void *arg, bool last_close) /* * default: just flush output buffer */ - sc = rtems_semaphore_obtain(tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) { - rtems_fatal_error_occurred (sc); - } + rtems_mutex_lock (&tty->osem); drainOutput (tty); - rtems_semaphore_release (tty->osem); + rtems_mutex_unlock (&tty->osem); } if (tty->handler.mode == TERMIOS_TASK_DRIVEN) { + rtems_status_code sc; + /* * send "terminate" to I/O tasks */ @@ -321,15 +307,15 @@ rtems_termios_destroy_tty (rtems_termios_tty *tty, void *arg, bool last_close) if (tty->device_node != NULL) tty->device_node->tty = NULL; - rtems_semaphore_delete (tty->isem); - rtems_semaphore_delete (tty->osem); - rtems_semaphore_delete (tty->rawOutBuf.Semaphore); + rtems_mutex_destroy (&tty->isem); + rtems_mutex_destroy (&tty->osem); + rtems_binary_semaphore_destroy (&tty->rawOutBuf.Semaphore); if ((tty->handler.poll_read == NULL) || (tty->handler.mode == TERMIOS_TASK_DRIVEN)) - rtems_semaphore_delete (tty->rawInBuf.Semaphore); + rtems_binary_semaphore_destroy (&tty->rawInBuf.Semaphore); if (needDeviceMutex (tty)) { - rtems_semaphore_delete (tty->device_context->lock.mutex); + rtems_mutex_destroy (&tty->device_context->lock.mutex); } else if (tty->device_context == &tty->legacy_device_context) { rtems_interrupt_lock_destroy (&tty->legacy_device_context.lock.interrupt); } @@ -346,11 +332,7 @@ deviceAcquireMutex( rtems_interrupt_lock_context *lock_context ) { - rtems_status_code sc; - - sc = rtems_semaphore_obtain (ctx->lock.mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - _Assert (sc == RTEMS_SUCCESSFUL); - (void) sc; + rtems_mutex_lock (&ctx->lock.mutex); } static void @@ -359,11 +341,7 @@ deviceReleaseMutex( rtems_interrupt_lock_context *lock_context ) { - rtems_status_code sc; - - sc = rtems_semaphore_release (ctx->lock.mutex); - _Assert (sc == RTEMS_SUCCESSFUL); - (void) sc; + rtems_mutex_unlock (&ctx->lock.mutex); } void @@ -451,30 +429,10 @@ rtems_termios_open_tty( /* * Set up mutex semaphores */ - sc = rtems_semaphore_create ( - rtems_build_name ('T', 'R', 'i', c), - 1, - RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, - RTEMS_NO_PRIORITY, - &tty->isem); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); - sc = rtems_semaphore_create ( - rtems_build_name ('T', 'R', 'o', c), - 1, - RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, - RTEMS_NO_PRIORITY, - &tty->osem); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); - sc = rtems_semaphore_create ( - rtems_build_name ('T', 'R', 'x', c), - 0, - RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_FIFO, - RTEMS_NO_PRIORITY, - &tty->rawOutBuf.Semaphore); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + rtems_mutex_init (&tty->isem, "termios input"); + rtems_mutex_init (&tty->osem, "termios output"); + rtems_binary_semaphore_init (&tty->rawOutBuf.Semaphore, + "termios raw output"); tty->rawOutBufState = rob_idle; /* @@ -520,16 +478,7 @@ rtems_termios_open_tty( ctx = tty->device_context; if (needDeviceMutex (tty)) { - sc = rtems_semaphore_create ( - rtems_build_name ('T', 'l', 'k', c), - 1, - RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, - 0, - &ctx->lock.mutex); - if (sc != RTEMS_SUCCESSFUL) { - rtems_fatal_error_occurred (sc); - } - + rtems_mutex_init (&ctx->lock.mutex, "termios device"); ctx->lock_acquire = deviceAcquireMutex; ctx->lock_release = deviceReleaseMutex; } else { @@ -565,12 +514,8 @@ rtems_termios_open_tty( } if ((tty->handler.poll_read == NULL) || (tty->handler.mode == TERMIOS_TASK_DRIVEN)){ - sc = rtems_semaphore_create ( - rtems_build_name ('T', 'R', 'r', c), - 0, - RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY, - RTEMS_NO_PRIORITY, - &tty->rawInBuf.Semaphore); + rtems_binary_semaphore_init (&tty->rawInBuf.Semaphore, + "termios raw input"); if (sc != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred (sc); } @@ -654,15 +599,12 @@ rtems_termios_open ( const rtems_termios_callbacks *callbacks ) { - rtems_status_code sc; struct rtems_termios_tty *tty; /* * See if the device has already been opened */ - sc = rtems_termios_obtain (); - if (sc != RTEMS_SUCCESSFUL) - return sc; + rtems_termios_obtain (); for (tty = rtems_termios_ttyHead ; tty != NULL ; tty = tty->forw) { if ((tty->major == major) && (tty->minor == minor)) @@ -730,13 +672,10 @@ rtems_termios_close_tty (rtems_termios_tty *tty, void *arg) rtems_status_code rtems_termios_close (void *arg) { - rtems_status_code sc; rtems_libio_open_close_args_t *args = arg; struct rtems_termios_tty *tty = args->iop->data1; - sc = rtems_termios_obtain (); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + rtems_termios_obtain (); if (tty->refcount == 1) { if (tty->forw == NULL) { @@ -854,11 +793,9 @@ rtems_termios_ioctl (void *arg) rtems_status_code sc; int flags; + sc = RTEMS_SUCCESSFUL; args->ioctl_return = 0; - sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) { - return sc; - } + rtems_mutex_lock (&tty->osem); switch (args->command) { default: if (rtems_termios_linesw[tty->t_line].l_ioctl != NULL) { @@ -891,26 +828,26 @@ rtems_termios_ioctl (void *arg) termios_set_flowctrl(tty); if (tty->termios.c_lflag & ICANON) { - tty->rawInBufSemaphoreOptions = RTEMS_WAIT; - tty->rawInBufSemaphoreTimeout = RTEMS_NO_TIMEOUT; - tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT; + tty->rawInBufSemaphoreWait = true; + tty->rawInBufSemaphoreTimeout = 0; + tty->rawInBufSemaphoreFirstTimeout = 0; } else { tty->vtimeTicks = tty->termios.c_cc[VTIME] * rtems_clock_get_ticks_per_second() / 10; if (tty->termios.c_cc[VTIME]) { - tty->rawInBufSemaphoreOptions = RTEMS_WAIT; + tty->rawInBufSemaphoreWait = true; tty->rawInBufSemaphoreTimeout = tty->vtimeTicks; if (tty->termios.c_cc[VMIN]) - tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT; + tty->rawInBufSemaphoreFirstTimeout = 0; else tty->rawInBufSemaphoreFirstTimeout = tty->vtimeTicks; } else { if (tty->termios.c_cc[VMIN]) { - tty->rawInBufSemaphoreOptions = RTEMS_WAIT; - tty->rawInBufSemaphoreTimeout = RTEMS_NO_TIMEOUT; - tty->rawInBufSemaphoreFirstTimeout = RTEMS_NO_TIMEOUT; + tty->rawInBufSemaphoreWait = true; + tty->rawInBufSemaphoreTimeout = 0; + tty->rawInBufSemaphoreFirstTimeout = 0; } else { - tty->rawInBufSemaphoreOptions = RTEMS_NO_WAIT; + tty->rawInBufSemaphoreWait = false; } } } @@ -983,7 +920,7 @@ rtems_termios_ioctl (void *arg) break; } - rtems_semaphore_release (tty->osem); + rtems_mutex_unlock (&tty->osem); return sc; } @@ -1040,7 +977,6 @@ doTransmit (const char *buf, size_t len, rtems_termios_tty *tty, unsigned int newHead; rtems_termios_device_context *ctx = tty->device_context; rtems_interrupt_lock_context lock_context; - rtems_status_code sc; size_t todo; if (tty->handler.mode == TERMIOS_POLLED) { @@ -1065,10 +1001,7 @@ doTransmit (const char *buf, size_t len, rtems_termios_tty *tty, do { tty->rawOutBufState = rob_wait; rtems_termios_device_lock_release (ctx, &lock_context); - sc = rtems_semaphore_obtain( - tty->rawOutBuf.Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + rtems_binary_semaphore_wait (&tty->rawOutBuf.Semaphore); rtems_termios_device_lock_acquire (ctx, &lock_context); } while (newHead == tty->rawOutBuf.Tail); } else { @@ -1256,20 +1189,19 @@ rtems_termios_write (void *arg) { rtems_libio_rw_args_t *args = arg; struct rtems_termios_tty *tty = args->iop->data1; - rtems_status_code sc; - sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - return sc; + rtems_mutex_lock (&tty->osem); if (rtems_termios_linesw[tty->t_line].l_write != NULL) { + rtems_status_code sc; + sc = rtems_termios_linesw[tty->t_line].l_write(tty,args); - rtems_semaphore_release (tty->osem); + rtems_mutex_unlock (&tty->osem); return sc; } args->bytes_moved = rtems_termios_write_tty (args->iop, tty, args->buffer, args->count); - rtems_semaphore_release (tty->osem); - return sc; + rtems_mutex_unlock (&tty->osem); + return RTEMS_SUCCESSFUL; } /* @@ -1440,14 +1372,9 @@ siproc (unsigned char c, struct rtems_termios_tty *tty) * Obtain output semaphore if character will be echoed */ if (tty->termios.c_lflag & (ECHO|ECHOE|ECHOK|ECHONL|ECHOPRT|ECHOCTL|ECHOKE)) { - rtems_status_code sc; - sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + rtems_mutex_lock (&tty->osem); i = iproc (c, tty); - sc = rtems_semaphore_release (tty->osem); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + rtems_mutex_unlock (&tty->osem); } else { i = iproc (c, tty); @@ -1591,12 +1518,20 @@ fillBufferQueue (struct rtems_termios_tty *tty) */ if (wait) { if (tty->ccount < CBUFSIZE - 1) { - rtems_status_code sc; + rtems_binary_semaphore *sem; + int eno; + + sem = &tty->rawInBuf.Semaphore; + + if (tty->rawInBufSemaphoreWait) { + eno = rtems_binary_semaphore_wait_timed_ticks (sem, timeout); + } else { + eno = rtems_binary_semaphore_try_wait (sem); + } - sc = rtems_semaphore_obtain( - tty->rawInBuf.Semaphore, tty->rawInBufSemaphoreOptions, timeout); - if (sc != RTEMS_SUCCESSFUL) + if (eno != 0) { break; + } } else { break; } @@ -1633,22 +1568,21 @@ rtems_termios_read (void *arg) { rtems_libio_rw_args_t *args = arg; struct rtems_termios_tty *tty = args->iop->data1; - rtems_status_code sc; - sc = rtems_semaphore_obtain (tty->isem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - return sc; + rtems_mutex_lock (&tty->isem); if (rtems_termios_linesw[tty->t_line].l_read != NULL) { + rtems_status_code sc; + sc = rtems_termios_linesw[tty->t_line].l_read(tty,args); tty->tty_rcvwakeup = false; - rtems_semaphore_release (tty->isem); + rtems_mutex_unlock (&tty->isem); return sc; } args->bytes_moved = rtems_termios_read_tty (tty, args->buffer, args->count); - rtems_semaphore_release (tty->isem); - return sc; + rtems_mutex_unlock (&tty->isem); + return RTEMS_SUCCESSFUL; } /* @@ -1826,7 +1760,7 @@ rtems_termios_enqueue_raw_characters (void *ttyp, const char *buf, int len) } tty->rawInBufDropped += dropped; - rtems_semaphore_release (tty->rawInBuf.Semaphore); + rtems_binary_semaphore_post (&tty->rawInBuf.Semaphore); return dropped; } @@ -1923,7 +1857,7 @@ rtems_termios_refill_transmitter (struct rtems_termios_tty *tty) rtems_termios_device_lock_release (ctx, &lock_context); if (wakeUpWriterTask) { - rtems_semaphore_release (tty->rawOutBuf.Semaphore); + rtems_binary_semaphore_post (&tty->rawOutBuf.Semaphore); } return nToSend; @@ -2062,7 +1996,6 @@ rtems_termios_imfs_open (rtems_libio_t *iop, const char *path, int oflag, mode_t mode) { rtems_termios_device_node *device_node; - rtems_status_code sc; rtems_libio_open_close_args_t args; struct rtems_termios_tty *tty; @@ -2073,10 +2006,7 @@ rtems_termios_imfs_open (rtems_libio_t *iop, args.flags = iop->flags; args.mode = mode; - sc = rtems_termios_obtain (); - if (sc != RTEMS_SUCCESSFUL) { - rtems_set_errno_and_return_minus_one (ENXIO); - } + rtems_termios_obtain (); tty = rtems_termios_open_tty (device_node->major, device_node->minor, &args, device_node->tty, device_node, NULL); @@ -2092,7 +2022,6 @@ rtems_termios_imfs_open (rtems_libio_t *iop, static int rtems_termios_imfs_close (rtems_libio_t *iop) { - rtems_status_code sc; rtems_libio_open_close_args_t args; struct rtems_termios_tty *tty; @@ -2101,10 +2030,7 @@ rtems_termios_imfs_close (rtems_libio_t *iop) tty = iop->data1; - sc = rtems_termios_obtain (); - _Assert (sc == RTEMS_SUCCESSFUL); - (void) sc; - + rtems_termios_obtain (); rtems_termios_close_tty (tty, &args); rtems_termios_release (); return 0; @@ -2114,16 +2040,15 @@ static ssize_t rtems_termios_imfs_read (rtems_libio_t *iop, void *buffer, size_t count) { struct rtems_termios_tty *tty; - rtems_status_code sc; uint32_t bytes_moved; tty = iop->data1; - sc = rtems_semaphore_obtain (tty->isem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - _Assert (sc == RTEMS_SUCCESSFUL); + rtems_mutex_lock (&tty->isem); if (rtems_termios_linesw[tty->t_line].l_read != NULL) { rtems_libio_rw_args_t args; + rtems_status_code sc; memset (&args, 0, sizeof (args)); args.iop = iop; @@ -2133,7 +2058,7 @@ rtems_termios_imfs_read (rtems_libio_t *iop, void *buffer, size_t count) sc = rtems_termios_linesw[tty->t_line].l_read (tty, &args); tty->tty_rcvwakeup = false; - rtems_semaphore_release (tty->isem); + rtems_mutex_unlock (&tty->isem); if (sc != RTEMS_SUCCESSFUL) { return rtems_status_code_to_errno (sc); @@ -2143,7 +2068,7 @@ rtems_termios_imfs_read (rtems_libio_t *iop, void *buffer, size_t count) } bytes_moved = rtems_termios_read_tty (tty, buffer, count); - rtems_semaphore_release (tty->isem); + rtems_mutex_unlock (&tty->isem); return (ssize_t) bytes_moved; } @@ -2151,16 +2076,15 @@ static ssize_t rtems_termios_imfs_write (rtems_libio_t *iop, const void *buffer, size_t count) { struct rtems_termios_tty *tty; - rtems_status_code sc; uint32_t bytes_moved; tty = iop->data1; - sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - _Assert (sc == RTEMS_SUCCESSFUL); + rtems_mutex_lock (&tty->osem); if (rtems_termios_linesw[tty->t_line].l_write != NULL) { rtems_libio_rw_args_t args; + rtems_status_code sc; memset (&args, 0, sizeof (args)); args.iop = iop; @@ -2169,7 +2093,7 @@ rtems_termios_imfs_write (rtems_libio_t *iop, const void *buffer, size_t count) args.flags = iop->flags; sc = rtems_termios_linesw[tty->t_line].l_write (tty, &args); - rtems_semaphore_release (tty->osem); + rtems_mutex_unlock (&tty->osem); if (sc != RTEMS_SUCCESSFUL) { return rtems_status_code_to_errno (sc); @@ -2179,7 +2103,7 @@ rtems_termios_imfs_write (rtems_libio_t *iop, const void *buffer, size_t count) } bytes_moved = rtems_termios_write_tty (iop, tty, buffer, count); - rtems_semaphore_release (tty->osem); + rtems_mutex_unlock (&tty->osem); return (ssize_t) bytes_moved; } diff --git a/cpukit/libcsupport/src/termiosinitialize.c b/cpukit/libcsupport/src/termiosinitialize.c index 46f40e3ea4..f89b8d1b47 100644 --- a/cpukit/libcsupport/src/termiosinitialize.c +++ b/cpukit/libcsupport/src/termiosinitialize.c @@ -22,34 +22,6 @@ #include "config.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include -rtems_id rtems_termios_ttyMutex; - -void -rtems_termios_initialize (void) -{ - rtems_status_code sc; - - /* - * Create the mutex semaphore for the tty list - */ - if (!rtems_termios_ttyMutex) { - sc = rtems_semaphore_create ( - rtems_build_name ('T', 'R', 'm', 'i'), - 1, - RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, - RTEMS_NO_PRIORITY, - &rtems_termios_ttyMutex); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); - } -} +rtems_mutex rtems_termios_ttyMutex = RTEMS_MUTEX_INITIALIZER( "termios" ); diff --git a/testsuites/libtests/termios01/init.c b/testsuites/libtests/termios01/init.c index 6f5e4f657c..1fd2c5789c 100644 --- a/testsuites/libtests/termios01/init.c +++ b/testsuites/libtests/termios01/init.c @@ -635,10 +635,11 @@ static rtems_status_code test_early_device_install( * after this test case. */ for (i = 0; i < 4; ++i) { - errno = 0; fd = open( &dev[0], O_RDWR ); - rtems_test_assert( fd == -1 ); - rtems_test_assert( errno == ENXIO ); + rtems_test_assert( fd == i ); + + rv = close( fd ); + rtems_test_assert( rv == 0 ); } rv = unlink( &dev[0] ); diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am index 561d2d73e0..9bd53c58a2 100644 --- a/testsuites/sptests/Makefile.am +++ b/testsuites/sptests/Makefile.am @@ -17,7 +17,7 @@ _SUBDIRS = \ sperror01 sperror02 sperror03 \ spfatal01 spfatal02 spfatal03 spfatal04 spfatal05 spfatal06 spfatal07 \ spfatal08 spfatal09 spfatal10 spfatal11 spfatal12 spfatal13 spfatal14 \ - spfatal15 spfatal16 spfatal17 spfatal18 spfatal19 spfatal20 \ + spfatal15 spfatal16 \ spfatal24 spfatal25 spfatal27\ spfifo01 spfifo02 spfifo03 spfifo04 spfifo05 \ spfreechain01 \ diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac index 54fb8f53c6..36ae9ac56a 100644 --- a/testsuites/sptests/configure.ac +++ b/testsuites/sptests/configure.ac @@ -187,10 +187,6 @@ spfatal13/Makefile spfatal14/Makefile spfatal15/Makefile spfatal16/Makefile -spfatal17/Makefile -spfatal18/Makefile -spfatal19/Makefile -spfatal20/Makefile spfatal24/Makefile spfatal25/Makefile spfatal27/Makefile diff --git a/testsuites/sptests/spfatal17/Makefile.am b/testsuites/sptests/spfatal17/Makefile.am deleted file mode 100644 index 8e7200b1cd..0000000000 --- a/testsuites/sptests/spfatal17/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ - -rtems_tests_PROGRAMS = spfatal17 -spfatal17_SOURCES = ../spfatal_support/init.c \ - ../spfatal_support/consume_sems.c \ - ../spfatal_support/system.h testcase.h - -dist_rtems_tests_DATA = spfatal17.scn -dist_rtems_tests_DATA += spfatal17.doc - -include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg -include $(top_srcdir)/../automake/compile.am -include $(top_srcdir)/../automake/leaf.am - -AM_CPPFLAGS += -I$(top_srcdir)/../support/include -AM_CPPFLAGS += -DSEMAPHORES_REMAINING=3 - -LINK_OBJS = $(spfatal17_OBJECTS) -LINK_LIBS = $(spfatal17_LDLIBS) - -spfatal17$(EXEEXT): $(spfatal17_OBJECTS) $(spfatal17_DEPENDENCIES) - @rm -f spfatal17$(EXEEXT) - $(make-exe) - -include $(top_srcdir)/../automake/local.am diff --git a/testsuites/sptests/spfatal17/spfatal17.doc b/testsuites/sptests/spfatal17/spfatal17.doc deleted file mode 100644 index 921d8a4aee..0000000000 --- a/testsuites/sptests/spfatal17/spfatal17.doc +++ /dev/null @@ -1,19 +0,0 @@ -# COPYRIGHT (c) 1989-2010. -# On-Line Applications Research Corporation (OAR). -# -# The license and distribution terms for this file may be -# found in the file LICENSE in this distribution or at -# http://www.rtems.org/license/LICENSE. -# - -This file describes the directives and concepts tested by this test set. - -test set name: spfatal17 - -directives: - - rtems_termios_open - -concepts: - -+ fatal error for one of the semaphore creates diff --git a/testsuites/sptests/spfatal17/spfatal17.scn b/testsuites/sptests/spfatal17/spfatal17.scn deleted file mode 100644 index 5f41a1d5c0..0000000000 --- a/testsuites/sptests/spfatal17/spfatal17.scn +++ /dev/null @@ -1,3 +0,0 @@ -*** TEST FATAL 17 *** -Fatal error (termios sem create #2) hit -*** END OF TEST FATAL 17 *** diff --git a/testsuites/sptests/spfatal17/testcase.h b/testsuites/sptests/spfatal17/testcase.h deleted file mode 100644 index a82edca551..0000000000 --- a/testsuites/sptests/spfatal17/testcase.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * COPYRIGHT (c) 1989-2010. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -/* generate fatal errors in termios.c - * rtems_semaphore_create( rtems_build_name ('T', 'R', 'x', c),...); - */ - -#define FATAL_ERROR_TEST_NAME "17" -#define FATAL_ERROR_DESCRIPTION "termios sem create #2" -#define FATAL_ERROR_EXPECTED_SOURCE INTERNAL_ERROR_RTEMS_API -#define FATAL_ERROR_EXPECTED_ERROR RTEMS_TOO_MANY - -#define FATAL_USE_TERMIOS_CONSOLE - -#define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \ - CONSUME_SEMAPHORE_DRIVERS - -void force_error() -{ - /* we will not run this far */ -} diff --git a/testsuites/sptests/spfatal18/Makefile.am b/testsuites/sptests/spfatal18/Makefile.am deleted file mode 100644 index 8e7e83a8bf..0000000000 --- a/testsuites/sptests/spfatal18/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ - -rtems_tests_PROGRAMS = spfatal18 -spfatal18_SOURCES = ../spfatal_support/init.c \ - ../spfatal_support/consume_sems.c \ - ../spfatal_support/system.h testcase.h - -dist_rtems_tests_DATA = spfatal18.scn -dist_rtems_tests_DATA += spfatal18.doc - -include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg -include $(top_srcdir)/../automake/compile.am -include $(top_srcdir)/../automake/leaf.am - -AM_CPPFLAGS += -I$(top_srcdir)/../support/include -AM_CPPFLAGS += -DSEMAPHORES_REMAINING=2 - -LINK_OBJS = $(spfatal18_OBJECTS) -LINK_LIBS = $(spfatal18_LDLIBS) - -spfatal18$(EXEEXT): $(spfatal18_OBJECTS) $(spfatal18_DEPENDENCIES) - @rm -f spfatal18$(EXEEXT) - $(make-exe) - -include $(top_srcdir)/../automake/local.am diff --git a/testsuites/sptests/spfatal18/spfatal18.doc b/testsuites/sptests/spfatal18/spfatal18.doc deleted file mode 100644 index ffc0c51902..0000000000 --- a/testsuites/sptests/spfatal18/spfatal18.doc +++ /dev/null @@ -1,19 +0,0 @@ -# COPYRIGHT (c) 1989-2010. -# On-Line Applications Research Corporation (OAR). -# -# The license and distribution terms for this file may be -# found in the file LICENSE in this distribution or at -# http://www.rtems.org/license/LICENSE. -# - -This file describes the directives and concepts tested by this test set. - -test set name: spfatal18 - -directives: - - rtems_termios_open - -concepts: - -+ fatal error for one of the semaphore creates diff --git a/testsuites/sptests/spfatal18/spfatal18.scn b/testsuites/sptests/spfatal18/spfatal18.scn deleted file mode 100644 index 8912a5829e..0000000000 --- a/testsuites/sptests/spfatal18/spfatal18.scn +++ /dev/null @@ -1,3 +0,0 @@ -*** TEST FATAL 18 *** -Fatal error (termios sem create #3) hit -*** END OF TEST FATAL 18 *** diff --git a/testsuites/sptests/spfatal18/testcase.h b/testsuites/sptests/spfatal18/testcase.h deleted file mode 100644 index ce1310ee35..0000000000 --- a/testsuites/sptests/spfatal18/testcase.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * COPYRIGHT (c) 1989-2010. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -/* generate fatal errors in termios.c - * rtems_semaphore_create( rtems_build_name ('T', 'R', 'o', c),...); - */ - -#define FATAL_ERROR_TEST_NAME "18" -#define FATAL_ERROR_DESCRIPTION "termios sem create #3" -#define FATAL_ERROR_EXPECTED_SOURCE INTERNAL_ERROR_RTEMS_API -#define FATAL_ERROR_EXPECTED_ERROR RTEMS_TOO_MANY - -#define FATAL_USE_TERMIOS_CONSOLE - -#define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \ - CONSUME_SEMAPHORE_DRIVERS - -void force_error() -{ - /* we will not run this far */ -} diff --git a/testsuites/sptests/spfatal19/Makefile.am b/testsuites/sptests/spfatal19/Makefile.am deleted file mode 100644 index b6884290c6..0000000000 --- a/testsuites/sptests/spfatal19/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ - -rtems_tests_PROGRAMS = spfatal19 -spfatal19_SOURCES = ../spfatal_support/init.c \ - ../spfatal_support/consume_sems.c \ - ../spfatal_support/system.h testcase.h - -dist_rtems_tests_DATA = spfatal19.scn -dist_rtems_tests_DATA += spfatal19.doc - -include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg -include $(top_srcdir)/../automake/compile.am -include $(top_srcdir)/../automake/leaf.am - -AM_CPPFLAGS += -I$(top_srcdir)/../support/include -AM_CPPFLAGS += -DSEMAPHORES_REMAINING=1 - -LINK_OBJS = $(spfatal19_OBJECTS) -LINK_LIBS = $(spfatal19_LDLIBS) - -spfatal19$(EXEEXT): $(spfatal19_OBJECTS) $(spfatal19_DEPENDENCIES) - @rm -f spfatal19$(EXEEXT) - $(make-exe) - -include $(top_srcdir)/../automake/local.am diff --git a/testsuites/sptests/spfatal19/spfatal19.doc b/testsuites/sptests/spfatal19/spfatal19.doc deleted file mode 100644 index a0d56703e3..0000000000 --- a/testsuites/sptests/spfatal19/spfatal19.doc +++ /dev/null @@ -1,19 +0,0 @@ -# COPYRIGHT (c) 1989-2010. -# On-Line Applications Research Corporation (OAR). -# -# The license and distribution terms for this file may be -# found in the file LICENSE in this distribution or at -# http://www.rtems.org/license/LICENSE. -# - -This file describes the directives and concepts tested by this test set. - -test set name: spfatal19 - -directives: - - rtems_termios_open - -concepts: - -+ fatal error for one of the semaphore creates diff --git a/testsuites/sptests/spfatal19/spfatal19.scn b/testsuites/sptests/spfatal19/spfatal19.scn deleted file mode 100644 index 6dd2901608..0000000000 --- a/testsuites/sptests/spfatal19/spfatal19.scn +++ /dev/null @@ -1,3 +0,0 @@ -*** TEST FATAL 19 *** -Fatal error (termios sem create #4) hit -*** END OF TEST FATAL 19 *** diff --git a/testsuites/sptests/spfatal19/testcase.h b/testsuites/sptests/spfatal19/testcase.h deleted file mode 100644 index 7b94ca4c9f..0000000000 --- a/testsuites/sptests/spfatal19/testcase.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * COPYRIGHT (c) 1989-2010. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -/* generate fatal errors in termios.c - * rtems_semaphore_create( rtems_build_name ('T', 'R', 'i', c),...); - */ - -#define FATAL_ERROR_TEST_NAME "19" -#define FATAL_ERROR_DESCRIPTION "termios sem create #4" -#define FATAL_ERROR_EXPECTED_SOURCE INTERNAL_ERROR_RTEMS_API -#define FATAL_ERROR_EXPECTED_ERROR RTEMS_TOO_MANY - -#define FATAL_USE_TERMIOS_CONSOLE - -#define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \ - CONSUME_SEMAPHORE_DRIVERS - -void force_error() -{ - /* we will not run this far */ -} diff --git a/testsuites/sptests/spfatal20/Makefile.am b/testsuites/sptests/spfatal20/Makefile.am deleted file mode 100644 index cf990b295d..0000000000 --- a/testsuites/sptests/spfatal20/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ - -rtems_tests_PROGRAMS = spfatal20 -spfatal20_SOURCES = ../spfatal_support/init.c \ - ../spfatal_support/consume_sems.c \ - ../spfatal_support/system.h testcase.h - -dist_rtems_tests_DATA = spfatal20.scn -dist_rtems_tests_DATA += spfatal20.doc - -include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg -include $(top_srcdir)/../automake/compile.am -include $(top_srcdir)/../automake/leaf.am - -AM_CPPFLAGS += -I$(top_srcdir)/../support/include -AM_CPPFLAGS += -DSEMAPHORES_REMAINING=0 - -LINK_OBJS = $(spfatal20_OBJECTS) -LINK_LIBS = $(spfatal20_LDLIBS) - -spfatal20$(EXEEXT): $(spfatal20_OBJECTS) $(spfatal20_DEPENDENCIES) - @rm -f spfatal20$(EXEEXT) - $(make-exe) - -include $(top_srcdir)/../automake/local.am diff --git a/testsuites/sptests/spfatal20/spfatal20.doc b/testsuites/sptests/spfatal20/spfatal20.doc deleted file mode 100644 index 245eeea617..0000000000 --- a/testsuites/sptests/spfatal20/spfatal20.doc +++ /dev/null @@ -1,19 +0,0 @@ -# COPYRIGHT (c) 1989-2010. -# On-Line Applications Research Corporation (OAR). -# -# The license and distribution terms for this file may be -# found in the file LICENSE in this distribution or at -# http://www.rtems.org/license/LICENSE. -# - -This file describes the directives and concepts tested by this test set. - -test set name: spfatal20 - -directives: - - rtems_termios_initialize - -concepts: - -+ fatal error for unable to create a semaphore diff --git a/testsuites/sptests/spfatal20/spfatal20.scn b/testsuites/sptests/spfatal20/spfatal20.scn deleted file mode 100644 index fa8c3009d2..0000000000 --- a/testsuites/sptests/spfatal20/spfatal20.scn +++ /dev/null @@ -1,3 +0,0 @@ -*** TEST FATAL 20 *** -Fatal error (rtems_termios_initialize cannot create semaphore) hit -*** END OF TEST FATAL 20 *** diff --git a/testsuites/sptests/spfatal20/testcase.h b/testsuites/sptests/spfatal20/testcase.h deleted file mode 100644 index 715854c461..0000000000 --- a/testsuites/sptests/spfatal20/testcase.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * COPYRIGHT (c) 1989-2010. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. - */ - -#define FATAL_ERROR_TEST_NAME "20" -#define FATAL_ERROR_DESCRIPTION \ - "rtems_termios_initialize cannot create semaphore" -#define FATAL_ERROR_EXPECTED_SOURCE INTERNAL_ERROR_RTEMS_API -#define FATAL_ERROR_EXPECTED_ERROR RTEMS_TOO_MANY - -#define FATAL_USE_TERMIOS_CONSOLE - -#define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \ - CONSUME_SEMAPHORE_DRIVERS - -void force_error() -{ - /* we will not run this far */ -} diff --git a/testsuites/sptests/spfatal_support/system.h b/testsuites/sptests/spfatal_support/system.h index 8fe68ad716..1dc0d8b19b 100644 --- a/testsuites/sptests/spfatal_support/system.h +++ b/testsuites/sptests/spfatal_support/system.h @@ -71,11 +71,7 @@ extern rtems_extensions_table initial_extensions; RTEMS_TEST_INITIAL_EXTENSION /* extra parameters may be in testcase.h */ -#ifdef FATAL_USE_TERMIOS_CONSOLE -#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER -#else #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER -#endif #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER /* always need an Init task, some cases need more tasks */ -- cgit v1.2.3