[PATCH 4/6] termios: Use C11 mutex for global state

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Dec 14 13:39:40 UTC 2016


Update #2840.
---
 cpukit/libcsupport/include/rtems/libio.h        |  5 +++-
 cpukit/libcsupport/include/rtems/termiostypes.h |  2 ++
 cpukit/libcsupport/src/termios.c                | 36 ++++++-------------------
 cpukit/libcsupport/src/termiosinitialize.c      | 32 ++--------------------
 cpukit/sapi/include/confdefs.h                  |  2 +-
 testsuites/sptests/Makefile.am                  |  2 +-
 testsuites/sptests/configure.ac                 |  1 -
 testsuites/sptests/spfatal20/Makefile.am        | 24 -----------------
 testsuites/sptests/spfatal20/spfatal20.doc      | 19 -------------
 testsuites/sptests/spfatal20/spfatal20.scn      |  3 ---
 testsuites/sptests/spfatal20/testcase.h         | 22 ---------------
 11 files changed, 18 insertions(+), 130 deletions(-)
 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/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h
index a87031c..4310cba 100644
--- a/cpukit/libcsupport/include/rtems/libio.h
+++ b/cpukit/libcsupport/include/rtems/libio.h
@@ -1808,7 +1808,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 only for backward/forward compatibility */
+}
 
 /*
  * CCJ: Change before opening a tty. Newer code from Eric is coming
diff --git a/cpukit/libcsupport/include/rtems/termiostypes.h b/cpukit/libcsupport/include/rtems/termiostypes.h
index 0a9da78..7ed6098 100644
--- a/cpukit/libcsupport/include/rtems/termiostypes.h
+++ b/cpukit/libcsupport/include/rtems/termiostypes.h
@@ -28,6 +28,8 @@
 extern "C" {
 #endif
 
+extern mtx_t rtems_termios_ttyMutex;
+
 /**
  *  @defgroup TermiostypesSupport RTEMS Termios Device Support
  *
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index 6ff6043..99bca7c 100644
--- a/cpukit/libcsupport/src/termios.c
+++ b/cpukit/libcsupport/src/termios.c
@@ -81,8 +81,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 = 128;
 static size_t rtems_termios_raw_output_size = 64;
@@ -156,21 +154,16 @@ inputUnlock (rtems_termios_tty *tty)
   unlock (&tty->imtx);
 }
 
-static rtems_status_code
+static void
 rtems_termios_obtain (void)
 {
-  return rtems_semaphore_obtain (rtems_termios_ttyMutex, RTEMS_WAIT,
-    RTEMS_NO_TIMEOUT);
+  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;
+  unlock (&rtems_termios_ttyMutex);
 }
 
 rtems_status_code rtems_termios_device_install(
@@ -658,15 +651,13 @@ rtems_termios_open (
   const rtems_termios_callbacks *callbacks
 )
 {
-  rtems_status_code sc;
   struct rtems_termios_tty *tty;
 
+  rtems_termios_obtain ();
+
   /*
    * See if the device has already been opened
    */
-  sc = rtems_termios_obtain ();
-  if (sc != RTEMS_SUCCESSFUL)
-    return sc;
 
   for (tty = rtems_termios_ttyHead ; tty != NULL ; tty = tty->forw) {
     if ((tty->major == major) && (tty->minor == minor))
@@ -734,13 +725,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) {
@@ -1912,7 +1900,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;
 
@@ -1923,10 +1910,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);
@@ -1942,7 +1926,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;
 
@@ -1951,10 +1934,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;
diff --git a/cpukit/libcsupport/src/termiosinitialize.c b/cpukit/libcsupport/src/termiosinitialize.c
index 46f40e3..fb9948b 100644
--- a/cpukit/libcsupport/src/termiosinitialize.c
+++ b/cpukit/libcsupport/src/termiosinitialize.c
@@ -22,34 +22,6 @@
 #include "config.h"
 #endif
 
-#include <rtems.h>
-#include <rtems.h>
-#include <rtems/libio.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <termios.h>
-#include <unistd.h>
+#include <rtems/termiostypes.h>
 
-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);
-  }
-}
+mtx_t rtems_termios_ttyMutex;
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index aa5fc08..12e488a 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -185,7 +185,7 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
    * based upon the number of communication ports that will use it.
    */
   #define CONFIGURE_TERMIOS_SEMAPHORES \
-    ((CONFIGURE_NUMBER_OF_TERMIOS_PORTS * 2) + 1)
+    (CONFIGURE_NUMBER_OF_TERMIOS_PORTS * 2)
 #endif
 
 /**
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index 5b48fc6..c3fef08 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 spfatal20 \
+    spfatal15 spfatal16 spfatal17 \
     spfatal24 spfatal25 spfatal27\
     spfifo01 spfifo02 spfifo03 spfifo04 spfifo05 \
     spfreechain01 \
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index c844951..f4fc800 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -187,7 +187,6 @@ spfatal14/Makefile
 spfatal15/Makefile
 spfatal16/Makefile
 spfatal17/Makefile
-spfatal20/Makefile
 spfatal24/Makefile
 spfatal25/Makefile
 spfatal27/Makefile
diff --git a/testsuites/sptests/spfatal20/Makefile.am b/testsuites/sptests/spfatal20/Makefile.am
deleted file mode 100644
index cf990b2..0000000
--- 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 at .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 245eeea..0000000
--- 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 fa8c300..0000000
--- 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 863982a..0000000
--- a/testsuites/sptests/spfatal20/testcase.h
+++ /dev/null
@@ -1,22 +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 CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \
-  CONSUME_SEMAPHORE_DRIVERS
-
-void force_error()
-{
-  /* we will not run this far */
-}
-- 
1.8.4.5



More information about the devel mailing list