[PATCH 3/3] posix: Unconditional thread attribute support
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Oct 9 13:55:06 UTC 2017
Update #2514.
---
cpukit/posix/Makefile.am | 29 +++++----
cpukit/posix/include/rtems/posix/pthreadattrimpl.h | 71 ++++++++++++++++++++++
cpukit/posix/include/rtems/posix/pthreadimpl.h | 29 ---------
cpukit/posix/preinstall.am | 4 ++
cpukit/posix/src/pthread.c | 54 ----------------
cpukit/posix/src/pthreadattrdefault.c | 60 ++++++++++++++++++
cpukit/posix/src/pthreadattrdestroy.c | 3 +-
cpukit/posix/src/pthreadattrinit.c | 6 +-
cpukit/posix/src/pthreadattrsetguardsize.c | 4 +-
cpukit/posix/src/pthreadattrsetinheritsched.c | 3 -
cpukit/posix/src/pthreadattrsetschedpolicy.c | 3 -
cpukit/posix/src/pthreadattrsetscope.c | 3 -
cpukit/posix/src/pthreadattrsetstack.c | 9 +--
cpukit/posix/src/pthreadattrsetstacksize.c | 8 +--
14 files changed, 156 insertions(+), 130 deletions(-)
create mode 100644 cpukit/posix/include/rtems/posix/pthreadattrimpl.h
create mode 100644 cpukit/posix/src/pthreadattrdefault.c
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index 7bd6869c3c..cbdd22bd3a 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -24,6 +24,7 @@ include_rtems_posix_HEADERS += include/rtems/posix/config.h
include_rtems_posix_HEADERS += include/rtems/posix/muteximpl.h
include_rtems_posix_HEADERS += include/rtems/posix/posixapi.h
include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h
+include_rtems_posix_HEADERS += include/rtems/posix/pthreadattrimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/rwlockimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/semaphore.h
include_rtems_posix_HEADERS += include/rtems/posix/semaphoreimpl.h
@@ -89,14 +90,25 @@ libposix_a_SOURCES += src/mutexattrdestroy.c src/mutexattrgetprioceiling.c \
src/mutexlocksupp.c src/mutexsetprioceiling.c src/mutextimedlock.c \
src/mutextrylock.c src/mutexunlock.c
+## PTHREAD_ATTR_C_FILES
+libposix_a_SOURCES += src/pthreadattrdefault.c src/pthreadattrdestroy.c \
+ src/pthreadattrgetdetachstate.c src/pthreadattrgetguardsize.c \
+ src/pthreadattrgetinheritsched.c src/pthreadattrgetschedparam.c \
+ src/pthreadattrgetschedpolicy.c src/pthreadattrgetscope.c \
+ src/pthreadattrgetstackaddr.c src/pthreadattrgetstack.c \
+ src/pthreadattrgetstacksize.c src/pthreadattrinit.c \
+ src/pthreadattrsetdetachstate.c src/pthreadattrsetguardsize.c \
+ src/pthreadattrsetinheritsched.c src/pthreadattrsetschedparam.c \
+ src/pthreadattrsetschedpolicy.c src/pthreadattrsetscope.c \
+ src/pthreadattrsetstackaddr.c src/pthreadattrsetstack.c \
+ src/pthreadattrsetstacksize.c
+
## PTHREAD_AFFINITY_C_FILES
libposix_a_SOURCES += src/pthreadattrsetaffinitynp.c \
src/pthreadattrgetaffinitynp.c src/pthreadgetaffinitynp.c \
src/pthreadsetaffinitynp.c
if HAS_PTHREADS
-libposix_a_SOURCES += src/pthreadatfork.c
-
## CANCEL_C_FILES
libposix_a_SOURCES += src/cancel.c \
src/cleanuppush.c src/setcancelstate.c \
@@ -128,18 +140,9 @@ libposix_a_SOURCES += src/mqueue.c src/mqueueclose.c \
src/mqueueunlink.c
## PTHREAD_C_FILES
-libposix_a_SOURCES += src/pthreadatfork.c src/pthreadattrdestroy.c \
- src/pthreadattrgetdetachstate.c src/pthreadattrgetinheritsched.c \
- src/pthreadattrgetschedparam.c src/pthreadattrgetschedpolicy.c \
- src/pthreadattrgetscope.c src/pthreadattrgetstackaddr.c \
- src/pthreadattrgetstack.c src/pthreadattrgetstacksize.c \
- src/pthreadattrinit.c src/pthreadattrsetdetachstate.c \
- src/pthreadattrsetguardsize.c src/pthreadattrsetinheritsched.c \
- src/pthreadattrsetschedparam.c src/pthreadattrsetschedpolicy.c \
- src/pthreadattrsetscope.c src/pthreadattrsetstackaddr.c \
- src/pthreadattrsetstack.c src/pthreadattrsetstacksize.c \
+libposix_a_SOURCES += src/pthreadatfork.c \
src/pthreadgetattrnp.c \
- src/pthreadattrgetguardsize.c src/pthread.c \
+ src/pthread.c \
src/pthreadconcurrency.c \
src/pthreadcreate.c src/pthreaddetach.c src/pthreadequal.c \
src/pthreadexit.c src/pthreadgetcpuclockid.c \
diff --git a/cpukit/posix/include/rtems/posix/pthreadattrimpl.h b/cpukit/posix/include/rtems/posix/pthreadattrimpl.h
new file mode 100644
index 0000000000..f1eaea98a4
--- /dev/null
+++ b/cpukit/posix/include/rtems/posix/pthreadattrimpl.h
@@ -0,0 +1,71 @@
+/**
+ * @file
+ *
+ * @brief POSIX Threads Private Support
+ *
+ * This include file contains all the private support information for
+ * POSIX threads.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * 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.
+ */
+
+#ifndef _RTEMS_POSIX_PTHREADATTRIMPL_H
+#define _RTEMS_POSIX_PTHREADATTRIMPL_H
+
+#include <errno.h>
+#include <pthread.h>
+
+#include <rtems/score/basedefs.h>
+#include <rtems/score/assert.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup POSIX_PTHREAD
+ */
+/**@{**/
+
+/**
+ * This variable contains the default POSIX Thread attributes.
+ */
+extern pthread_attr_t _POSIX_Threads_Default_attributes;
+
+RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
+ pthread_attr_t *dst_attr,
+ const pthread_attr_t *src_attr
+)
+{
+ *dst_attr = *src_attr;
+ _Assert(
+ dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated)
+ );
+ dst_attr->affinityset = &dst_attr->affinitysetpreallocated;
+}
+
+RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
+ pthread_attr_t *attr
+)
+{
+ _POSIX_Threads_Copy_attributes(
+ attr,
+ &_POSIX_Threads_Default_attributes
+ );
+}
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h b/cpukit/posix/include/rtems/posix/pthreadimpl.h
index 9e5314b2c2..055043105b 100644
--- a/cpukit/posix/include/rtems/posix/pthreadimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h
@@ -48,11 +48,6 @@ extern "C" {
*/
extern Thread_Information _POSIX_Threads_Information;
-/**
- * This variable contains the default POSIX Thread attributes.
- */
-extern pthread_attr_t _POSIX_Threads_Default_attributes;
-
RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert(
Thread_Control *the_thread,
POSIX_API_Control *api
@@ -113,20 +108,6 @@ RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
_Objects_Allocate_unprotected( &_POSIX_Threads_Information.Objects );
}
-RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
- pthread_attr_t *dst_attr,
- const pthread_attr_t *src_attr
-)
-{
- *dst_attr = *src_attr;
-#if defined(RTEMS_SMP)
- _Assert(
- dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated)
- );
- dst_attr->affinityset = &dst_attr->affinitysetpreallocated;
-#endif
-}
-
RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free (
Thread_Control *the_pthread
)
@@ -134,16 +115,6 @@ RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free (
_Objects_Free( &_POSIX_Threads_Information.Objects, &the_pthread->Object );
}
-RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
- pthread_attr_t *attr
-)
-{
- _POSIX_Threads_Copy_attributes(
- attr,
- &_POSIX_Threads_Default_attributes
- );
-}
-
/** @} */
#ifdef __cplusplus
diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am
index 157be567c2..d96cbf75a7 100644
--- a/cpukit/posix/preinstall.am
+++ b/cpukit/posix/preinstall.am
@@ -59,6 +59,10 @@ $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h: include/rtems/posix/priorityimpl.
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
+$(PROJECT_INCLUDE)/rtems/posix/pthreadattrimpl.h: include/rtems/posix/pthreadattrimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/pthreadattrimpl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/pthreadattrimpl.h
+
$(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h: include/rtems/posix/rwlockimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/rwlockimpl.h
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 1d791df7eb..17f7fe3a82 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -43,45 +43,6 @@
Thread_Information _POSIX_Threads_Information;
-/*
- * The default pthreads attributes structure.
- *
- * NOTE: Be careful .. if the default attribute set changes,
- * _POSIX_Threads_Initialize_user_threads will need to be examined.
- */
-pthread_attr_t _POSIX_Threads_Default_attributes = {
- .is_initialized = true, /* is_initialized */
- .stackaddr = NULL, /* stackaddr */
- .stacksize = 0, /* stacksize -- will be adjusted to minimum */
- .contentionscope = PTHREAD_SCOPE_PROCESS, /* contentionscope */
- .inheritsched = PTHREAD_INHERIT_SCHED, /* inheritsched */
- .schedpolicy = SCHED_FIFO, /* schedpolicy */
- .schedparam =
- { /* schedparam */
- 2, /* sched_priority */
- #if defined(_POSIX_SPORADIC_SERVER) || \
- defined(_POSIX_THREAD_SPORADIC_SERVER)
- 0, /* sched_ss_low_priority */
- { 0L, 0 }, /* sched_ss_repl_period */
- { 0L, 0 }, /* sched_ss_init_budget */
- 0 /* sched_ss_max_repl */
- #endif
- },
-
- #if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
- .guardsize = 0, /* guardsize */
- #endif
- #if defined(_POSIX_THREAD_CPUTIME)
- .cputime_clock_allowed = 1, /* cputime_clock_allowed */
- #endif
- .detachstate = PTHREAD_CREATE_JOINABLE, /* detachstate */
- .affinitysetsize =
- sizeof( _POSIX_Threads_Default_attributes.affinitysetpreallocated ),
- .affinityset =
- &_POSIX_Threads_Default_attributes.affinitysetpreallocated,
- .affinitysetpreallocated = {{0x1}}
-};
-
void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog )
{
POSIX_API_Control *api;
@@ -243,21 +204,6 @@ User_extensions_Control _POSIX_Threads_User_extensions = {
*/
static void _POSIX_Threads_Manager_initialization(void)
{
- #if defined(RTEMS_SMP)
- const CPU_set_Control *affinity;
- pthread_attr_t *attr;
-
- /* Initialize default attribute. */
- attr = &_POSIX_Threads_Default_attributes;
-
- /* Initialize the affinity to be the default cpu set for the system */
- affinity = _CPU_set_Default();
- _Assert( affinity->setsize == sizeof( attr->affinitysetpreallocated ) );
- attr->affinityset = &attr->affinitysetpreallocated;
- attr->affinitysetsize = affinity->setsize;
- CPU_COPY( affinity->set, attr->affinityset );
- #endif
-
_Thread_Initialize_information(
&_POSIX_Threads_Information, /* object information table */
OBJECTS_POSIX_API, /* object API */
diff --git a/cpukit/posix/src/pthreadattrdefault.c b/cpukit/posix/src/pthreadattrdefault.c
new file mode 100644
index 0000000000..15f0db1bf0
--- /dev/null
+++ b/cpukit/posix/src/pthreadattrdefault.c
@@ -0,0 +1,60 @@
+/**
+ * @file
+ *
+ * @brief Private Support Information for POSIX Threads
+ * @ingroup POSIX_PTHREADS Private Threads
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2014.
+ * 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.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/posix/pthreadattrimpl.h>
+
+/*
+ * The default pthreads attributes structure.
+ *
+ * NOTE: Be careful .. if the default attribute set changes,
+ * _POSIX_Threads_Initialize_user_threads will need to be examined.
+ */
+pthread_attr_t _POSIX_Threads_Default_attributes = {
+ .is_initialized = true, /* is_initialized */
+ .stackaddr = NULL, /* stackaddr */
+ .stacksize = 0, /* stacksize -- will be adjusted to minimum */
+ .contentionscope = PTHREAD_SCOPE_PROCESS, /* contentionscope */
+ .inheritsched = PTHREAD_INHERIT_SCHED, /* inheritsched */
+ .schedpolicy = SCHED_FIFO, /* schedpolicy */
+ .schedparam =
+ { /* schedparam */
+ 2, /* sched_priority */
+ #if defined(_POSIX_SPORADIC_SERVER) || \
+ defined(_POSIX_THREAD_SPORADIC_SERVER)
+ 0, /* sched_ss_low_priority */
+ { 0L, 0 }, /* sched_ss_repl_period */
+ { 0L, 0 }, /* sched_ss_init_budget */
+ 0 /* sched_ss_max_repl */
+ #endif
+ },
+
+ #if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
+ .guardsize = 0, /* guardsize */
+ #endif
+ #if defined(_POSIX_THREAD_CPUTIME)
+ .cputime_clock_allowed = 1, /* cputime_clock_allowed */
+ #endif
+ .detachstate = PTHREAD_CREATE_JOINABLE, /* detachstate */
+ .affinitysetsize =
+ sizeof( _POSIX_Threads_Default_attributes.affinitysetpreallocated ),
+ .affinityset =
+ &_POSIX_Threads_Default_attributes.affinitysetpreallocated,
+ .affinitysetpreallocated = { { -1L } }
+};
diff --git a/cpukit/posix/src/pthreadattrdestroy.c b/cpukit/posix/src/pthreadattrdestroy.c
index d36c1d6dfe..7d30be9ed5 100644
--- a/cpukit/posix/src/pthreadattrdestroy.c
+++ b/cpukit/posix/src/pthreadattrdestroy.c
@@ -20,8 +20,7 @@
#include <pthread.h>
#include <errno.h>
-
-#include <rtems/system.h>
+#include <stdbool.h>
int pthread_attr_destroy(
pthread_attr_t *attr
diff --git a/cpukit/posix/src/pthreadattrinit.c b/cpukit/posix/src/pthreadattrinit.c
index 311e42cc7a..d69cac497b 100644
--- a/cpukit/posix/src/pthreadattrinit.c
+++ b/cpukit/posix/src/pthreadattrinit.c
@@ -18,11 +18,7 @@
#include "config.h"
#endif
-#include <pthread.h>
-#include <errno.h>
-
-#include <rtems/system.h>
-#include <rtems/posix/pthreadimpl.h>
+#include <rtems/posix/pthreadattrimpl.h>
/**
* 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140
diff --git a/cpukit/posix/src/pthreadattrsetguardsize.c b/cpukit/posix/src/pthreadattrsetguardsize.c
index 829a1b30c6..766066ce24 100644
--- a/cpukit/posix/src/pthreadattrsetguardsize.c
+++ b/cpukit/posix/src/pthreadattrsetguardsize.c
@@ -19,12 +19,10 @@
#endif
#if HAVE_DECL_PTHREAD_ATTR_SETGUARDSIZE
+
#include <pthread.h>
#include <errno.h>
-#include <rtems/system.h>
-#include <rtems/posix/pthreadimpl.h>
-
int pthread_attr_setguardsize(
pthread_attr_t *attr,
size_t guardsize
diff --git a/cpukit/posix/src/pthreadattrsetinheritsched.c b/cpukit/posix/src/pthreadattrsetinheritsched.c
index 8ce3a5db0e..c3b8a53053 100644
--- a/cpukit/posix/src/pthreadattrsetinheritsched.c
+++ b/cpukit/posix/src/pthreadattrsetinheritsched.c
@@ -23,9 +23,6 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/system.h>
-#include <rtems/posix/pthreadimpl.h>
-
int pthread_attr_setinheritsched(
pthread_attr_t *attr,
int inheritsched
diff --git a/cpukit/posix/src/pthreadattrsetschedpolicy.c b/cpukit/posix/src/pthreadattrsetschedpolicy.c
index 9adec1b8f9..235e7a8ad1 100644
--- a/cpukit/posix/src/pthreadattrsetschedpolicy.c
+++ b/cpukit/posix/src/pthreadattrsetschedpolicy.c
@@ -23,9 +23,6 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/system.h>
-#include <rtems/posix/pthreadimpl.h>
-
int pthread_attr_setschedpolicy(
pthread_attr_t *attr,
int policy
diff --git a/cpukit/posix/src/pthreadattrsetscope.c b/cpukit/posix/src/pthreadattrsetscope.c
index 78b0fde984..1d8bec0467 100644
--- a/cpukit/posix/src/pthreadattrsetscope.c
+++ b/cpukit/posix/src/pthreadattrsetscope.c
@@ -23,9 +23,6 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/system.h>
-#include <rtems/posix/pthreadimpl.h>
-
int pthread_attr_setscope(
pthread_attr_t *attr,
int contentionscope
diff --git a/cpukit/posix/src/pthreadattrsetstack.c b/cpukit/posix/src/pthreadattrsetstack.c
index 3f62247741..b335274d92 100644
--- a/cpukit/posix/src/pthreadattrsetstack.c
+++ b/cpukit/posix/src/pthreadattrsetstack.c
@@ -22,9 +22,6 @@
#if HAVE_DECL_PTHREAD_ATTR_SETSTACK
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/score/stackimpl.h>
-
#include <pthread.h>
#include <errno.h>
@@ -37,11 +34,7 @@ int pthread_attr_setstack(
if ( !attr || !attr->is_initialized )
return EINVAL;
- if (stacksize < PTHREAD_MINIMUM_STACK_SIZE)
- attr->stacksize = PTHREAD_MINIMUM_STACK_SIZE;
- else
- attr->stacksize = stacksize;
-
+ attr->stacksize = stacksize;
attr->stackaddr = stackaddr;
return 0;
}
diff --git a/cpukit/posix/src/pthreadattrsetstacksize.c b/cpukit/posix/src/pthreadattrsetstacksize.c
index 4dae0f359e..b54531daae 100644
--- a/cpukit/posix/src/pthreadattrsetstacksize.c
+++ b/cpukit/posix/src/pthreadattrsetstacksize.c
@@ -20,9 +20,6 @@
#include "config.h"
#endif
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/score/stackimpl.h>
-
#include <pthread.h>
#include <errno.h>
@@ -34,9 +31,6 @@ int pthread_attr_setstacksize(
if ( !attr || !attr->is_initialized )
return EINVAL;
- if (stacksize < PTHREAD_MINIMUM_STACK_SIZE)
- attr->stacksize = PTHREAD_MINIMUM_STACK_SIZE;
- else
- attr->stacksize = stacksize;
+ attr->stacksize = stacksize;
return 0;
}
--
2.12.3
More information about the devel
mailing list