[PATCH 1/5] Add pthread_getconcurrency() and pthread_setconcurrency()

Joel Sherrill joel at rtems.org
Tue Mar 29 21:17:04 UTC 2016


This is the very simple implementation specified by the Open Group
for implementations with 1:1 kernel thread to user thread mappings.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getconcurrency.html

updates #2680.
---
 cpukit/posix/Makefile.am                           |  1 +
 cpukit/posix/src/pthreadconcurrency.c              | 42 ++++++++++++++++
 testsuites/psxtests/Makefile.am                    |  2 +-
 testsuites/psxtests/configure.ac                   |  1 +
 testsuites/psxtests/psxconcurrency01/Makefile.am   | 23 +++++++++
 testsuites/psxtests/psxconcurrency01/init.c        | 58 ++++++++++++++++++++++
 .../psxtests/psxconcurrency01/psxconcurrency01.doc | 25 ++++++++++
 .../psxtests/psxconcurrency01/psxconcurrency01.scn |  5 ++
 testsuites/psxtests/psxhdrs/Makefile.am            |  2 +
 .../psxhdrs/pthread/pthread_getconcurrency.c       | 34 +++++++++++++
 .../psxhdrs/pthread/pthread_setconcurrency.c       | 37 ++++++++++++++
 11 files changed, 229 insertions(+), 1 deletion(-)
 create mode 100644 cpukit/posix/src/pthreadconcurrency.c
 create mode 100644 testsuites/psxtests/psxconcurrency01/Makefile.am
 create mode 100644 testsuites/psxtests/psxconcurrency01/init.c
 create mode 100644 testsuites/psxtests/psxconcurrency01/psxconcurrency01.doc
 create mode 100644 testsuites/psxtests/psxconcurrency01/psxconcurrency01.scn
 create mode 100644 testsuites/psxtests/psxhdrs/pthread/pthread_getconcurrency.c
 create mode 100644 testsuites/psxtests/psxhdrs/pthread/pthread_setconcurrency.c

diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index dcedf5b..a72daae 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -126,6 +126,7 @@ libposix_a_SOURCES += src/pthreadatfork.c src/pthreadattrdestroy.c \
     src/pthreadattrsetstack.c src/pthreadattrsetstacksize.c \
     src/pthreadgetattrnp.c \
     src/pthreadattrgetguardsize.c src/pthread.c \
+    src/pthreadconcurrency.c \
     src/pthreadcreate.c src/pthreaddetach.c src/pthreadequal.c \
     src/pthreadexit.c src/pthreadgetcpuclockid.c \
     src/pthreadgetschedparam.c \
diff --git a/cpukit/posix/src/pthreadconcurrency.c b/cpukit/posix/src/pthreadconcurrency.c
new file mode 100644
index 0000000..7e9c9c0
--- /dev/null
+++ b/cpukit/posix/src/pthreadconcurrency.c
@@ -0,0 +1,42 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/**
+ * @file
+ *
+ * @brief Pthread Get/Set Concurrency
+ * @ingroup POSIXAPI
+ *
+ * Per the Open Group specification, when user pthreads are mapped 1:1
+ * onto kernel threads, the implementation simply tracks an internal
+ * variable whose initial value is 0. If it is set, subsequent calls to
+ * obtain the value return that previously set.
+ */
+
+/*
+ *  COPYRIGHT (c) 2016.
+ *  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.
+ */
+
+#include <pthread.h>
+#include <errno.h>
+
+static int pthread_concurrency_level;
+
+int pthread_getconcurrency(void)
+{
+  return pthread_concurrency_level;
+}
+
+int pthread_setconcurrency(
+  int new_level
+)
+{
+  pthread_concurrency_level = new_level;
+  return 0;
+}
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index bb89cde..6dd5649 100644
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -7,7 +7,7 @@ _SUBDIRS += psxhdrs psx01 psx02 psx03 psx04 psx05 psx06 psx07 psx08 psx09 \
     psxaio01 psxaio02 psxaio03 \
     psxalarm01 psxautoinit01 psxautoinit02 psxbarrier01 \
     psxcancel psxcancel01 psxclassic01 psxcleanup psxcleanup01 \
-    psxcond01 psxconfig01 psxenosys \
+    psxconcurrency01 psxcond01 psxconfig01 psxenosys \
     psxitimer psxmsgq01 psxmsgq02 psxmsgq03 psxmsgq04 \
     psxmutexattr01 psxobj01 psxrwlock01 psxsem01 psxsignal01 psxsignal02 \
     psxsignal03 psxsignal04 psxsignal05 psxsignal06 \
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index 67ef83e..779e0b5 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -143,6 +143,7 @@ psxcleanup01/Makefile
 psxcleanup02/Makefile
 psxclock/Makefile
 psxclock01/Makefile
+psxconcurrency01/Makefile
 psxcond01/Makefile
 psxconfig01/Makefile
 psxeintr_join/Makefile
diff --git a/testsuites/psxtests/psxconcurrency01/Makefile.am b/testsuites/psxtests/psxconcurrency01/Makefile.am
new file mode 100644
index 0000000..2be4ebb
--- /dev/null
+++ b/testsuites/psxtests/psxconcurrency01/Makefile.am
@@ -0,0 +1,23 @@
+
+rtems_tests_PROGRAMS = psxconcurrency01
+psxconcurrency01_SOURCES = init.c ../include/pmacros.h
+
+dist_rtems_tests_DATA = psxconcurrency01.scn
+dist_rtems_tests_DATA += psxconcurrency01.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)/include
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(psxconcurrency01_OBJECTS)
+LINK_LIBS = $(psxconcurrency01_LDLIBS)
+
+psxconcurrency01$(EXEEXT): $(psxconcurrency01_OBJECTS) $(psxconcurrency01_DEPENDENCIES)
+	@rm -f psxconcurrency01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxconcurrency01/init.c b/testsuites/psxtests/psxconcurrency01/init.c
new file mode 100644
index 0000000..60aef92
--- /dev/null
+++ b/testsuites/psxtests/psxconcurrency01/init.c
@@ -0,0 +1,58 @@
+/*
+ *  COPYRIGHT (c) 2016
+ *  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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pmacros.h>
+#include <pthread.h>
+#include <errno.h>
+
+const char rtems_test_name[] = "PSXCONCURRENCY01";
+
+/* forward declarations to avoid warnings */
+void *POSIX_Init(void *argument);
+
+void *POSIX_Init(
+  void *argument
+)
+{
+  int  sc;
+
+  TEST_BEGIN();
+
+  puts( "Init: pthread_getconcurrency - initial value of 0" );
+  sc = pthread_getconcurrency();
+  rtems_test_assert( sc == 0 );
+
+  puts( "Init: pthread_setconcurrency - set value to 2" );
+  sc = pthread_setconcurrency( 2 );
+  rtems_test_assert( sc == 0 );
+
+  puts( "Init: pthread_getconcurrency - confirm new value of 2" );
+  sc = pthread_getconcurrency();
+  rtems_test_assert( sc == 2 );
+
+  TEST_END();
+  rtems_test_exit(0);
+}
+
+
+/* configuration information */
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS     1
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
diff --git a/testsuites/psxtests/psxconcurrency01/psxconcurrency01.doc b/testsuites/psxtests/psxconcurrency01/psxconcurrency01.doc
new file mode 100644
index 0000000..62492ad
--- /dev/null
+++ b/testsuites/psxtests/psxconcurrency01/psxconcurrency01.doc
@@ -0,0 +1,25 @@
+#  COPYRIGHT (c) 2016.
+#  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:  psxconcurrency01
+
+directives:
+  pthread_getconcurrency
+  pthread_setconcurrency
+
+concepts:
+
++ This test exercises the pthread_getconcurrency() method.
++ This test exercises the pthread_setconcurrency() method.
+
+NOTE: These methods are of limited utility with any threading implementation
+      in which kernel threads and user threads are mapped 1:1. As of POSIX
+      Issue 7 (POSIX 2013), these are marked obsolete. But they are still
+      required for 2008 and Open Group FACE conformance.
diff --git a/testsuites/psxtests/psxconcurrency01/psxconcurrency01.scn b/testsuites/psxtests/psxconcurrency01/psxconcurrency01.scn
new file mode 100644
index 0000000..53eca04
--- /dev/null
+++ b/testsuites/psxtests/psxconcurrency01/psxconcurrency01.scn
@@ -0,0 +1,5 @@
+*** BEGIN OF TEST PSXCONCURRENCY01 ***
+Init: pthread_getconcurrency - initial value of 0
+Init: pthread_setconcurrency - set value to 2
+Init: pthread_getconcurrency - confirm new value of 2
+*** END OF TEST PSXCONCURRENCY01 ***
diff --git a/testsuites/psxtests/psxhdrs/Makefile.am b/testsuites/psxtests/psxhdrs/Makefile.am
index 8dc13e1..3eecd84 100644
--- a/testsuites/psxtests/psxhdrs/Makefile.am
+++ b/testsuites/psxtests/psxhdrs/Makefile.am
@@ -38,6 +38,7 @@ lib_a_SOURCES += pthread/pthread_create.c
 lib_a_SOURCES += pthread/pthread_detach.c
 lib_a_SOURCES += pthread/pthread_equal.c
 lib_a_SOURCES += pthread/pthread_exit.c
+lib_a_SOURCES += pthread/pthread_getconcurrency.c
 lib_a_SOURCES += pthread/pthread_getcpuclockid.c
 lib_a_SOURCES += pthread/pthread_getschedparam.c
 lib_a_SOURCES += pthread/pthread_getspecific.c
@@ -64,6 +65,7 @@ lib_a_SOURCES += pthread/pthread_once.c
 lib_a_SOURCES += pthread/pthread_self.c
 lib_a_SOURCES += pthread/pthread_setcancelstate.c
 lib_a_SOURCES += pthread/pthread_setcanceltype.c
+lib_a_SOURCES += pthread/pthread_setconcurrency.c
 lib_a_SOURCES += pthread/pthread_setschedparam.c
 lib_a_SOURCES += pthread/pthread_setspecific.c
 lib_a_SOURCES += pthread/pthread_testcancel.c
diff --git a/testsuites/psxtests/psxhdrs/pthread/pthread_getconcurrency.c b/testsuites/psxtests/psxhdrs/pthread/pthread_getconcurrency.c
new file mode 100644
index 0000000..dda4720
--- /dev/null
+++ b/testsuites/psxtests/psxhdrs/pthread/pthread_getconcurrency.c
@@ -0,0 +1,34 @@
+/**
+ *  @file
+ *  @brief pthread_getconcurrency() API Conformance Test
+ */
+
+/*
+ *  COPYRIGHT (c) 2016.
+ *  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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+
+#ifndef _POSIX_THREADS
+#error "rtems is supposed to have pthread_getconcurrency"
+#endif
+
+int test( void );
+
+int test( void )
+{
+  int level;
+
+  level = pthread_getconcurrency();
+
+  return (level == 0);
+}
diff --git a/testsuites/psxtests/psxhdrs/pthread/pthread_setconcurrency.c b/testsuites/psxtests/psxhdrs/pthread/pthread_setconcurrency.c
new file mode 100644
index 0000000..91b1889
--- /dev/null
+++ b/testsuites/psxtests/psxhdrs/pthread/pthread_setconcurrency.c
@@ -0,0 +1,37 @@
+/**
+ *  @file
+ *  @brief pthread_setconcurrency() API Conformance Test
+ */
+
+/*
+ *  COPYRIGHT (c) 2016.
+ *  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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+
+#ifndef _POSIX_THREADS
+#error "rtems is supposed to have pthread_setconcurrency"
+#endif
+
+int test( void );
+
+int test( void )
+{
+  int level;
+  int rc;
+
+  level = 42;
+
+  rc = pthread_setconcurrency( level );
+
+  return (rc == 0);
+}
-- 
1.8.3.1



More information about the devel mailing list