[rtems commit] posix: _POSIX_Mutex_Default_attributes
Sebastian Huber
sebh at rtems.org
Wed Jun 22 12:46:16 UTC 2016
Module: rtems
Branch: master
Commit: 2df7fcff883856cd2fa8a56e9c509a0674bfb01a
Changeset: http://git.rtems.org/rtems/commit/?id=2df7fcff883856cd2fa8a56e9c509a0674bfb01a
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Tue Jun 14 11:45:22 2016 +0200
posix: _POSIX_Mutex_Default_attributes
Make _POSIX_Mutex_Default_attributes constant and independent of the
scheduler instance. Use INT_MAX to indicate the default ceiling
priority.
---
cpukit/posix/Makefile.am | 2 +-
cpukit/posix/include/rtems/posix/muteximpl.h | 2 +-
cpukit/posix/include/rtems/posix/priorityimpl.h | 10 ++++++++
cpukit/posix/preinstall.am | 8 +++---
cpukit/posix/src/mutex.c | 33 +++++++++----------------
cpukit/posix/src/mutexinit.c | 14 +++++++++--
cpukit/posix/src/psxpriorityisvalid.c | 10 +++++++-
cpukit/posix/src/sched_getprioritymax.c | 10 ++------
8 files changed, 50 insertions(+), 39 deletions(-)
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index 2442f0c..5bf11c7 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -20,6 +20,7 @@ include_rtems_posix_HEADERS += include/rtems/posix/key.h
include_rtems_posix_HEADERS += include/rtems/posix/keyimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/config.h
include_rtems_posix_HEADERS += include/rtems/posix/posixapi.h
+include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h
if HAS_PTHREADS
# include
@@ -37,7 +38,6 @@ include_rtems_posix_HEADERS += include/rtems/posix/mqueue.h
include_rtems_posix_HEADERS += include/rtems/posix/mqueueimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/mutex.h
include_rtems_posix_HEADERS += include/rtems/posix/muteximpl.h
-include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/psignal.h
include_rtems_posix_HEADERS += include/rtems/posix/psignalimpl.h
include_rtems_posix_HEADERS += include/rtems/posix/pthread.h
diff --git a/cpukit/posix/include/rtems/posix/muteximpl.h b/cpukit/posix/include/rtems/posix/muteximpl.h
index 4957e20..7d19d8c 100644
--- a/cpukit/posix/include/rtems/posix/muteximpl.h
+++ b/cpukit/posix/include/rtems/posix/muteximpl.h
@@ -50,7 +50,7 @@ extern Objects_Information _POSIX_Mutex_Information;
/**
* The default mutex attributes structure.
*/
-extern pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
+extern const pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Acquire_critical(
POSIX_Mutex_Control *the_mutex,
diff --git a/cpukit/posix/include/rtems/posix/priorityimpl.h b/cpukit/posix/include/rtems/posix/priorityimpl.h
index 3835ee9..e3f23e7 100644
--- a/cpukit/posix/include/rtems/posix/priorityimpl.h
+++ b/cpukit/posix/include/rtems/posix/priorityimpl.h
@@ -60,6 +60,16 @@ extern "C" {
#define POSIX_SCHEDULER_MINIMUM_PRIORITY (1)
/**
+ * @brief Gets the maximum POSIX API priority for this scheduler instance.
+ *
+ * Such a priority is valid. A scheduler instance may support priority values
+ * that are not representable as an integer.
+ *
+ * @return The maximum POSIX API priority for this scheduler instance.
+ */
+int _POSIX_Priority_Get_maximum( const Scheduler_Control *scheduler );
+
+/**
* @brief Check if POSIX priority is valid.
*
* 1003.1b-1993,2.2.2.80 definition of priority, p. 19
diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am
index 6fc6b4c..1d035e7 100644
--- a/cpukit/posix/preinstall.am
+++ b/cpukit/posix/preinstall.am
@@ -43,6 +43,10 @@ $(PROJECT_INCLUDE)/rtems/posix/posixapi.h: include/rtems/posix/posixapi.h $(PROJ
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/posixapi.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/posixapi.h
+$(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h: include/rtems/posix/priorityimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
+
if HAS_PTHREADS
$(PROJECT_INCLUDE)/aio.h: include/aio.h $(PROJECT_INCLUDE)/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/aio.h
@@ -85,10 +89,6 @@ $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h: include/rtems/posix/muteximpl.h $(PR
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h
-$(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h: include/rtems/posix/priorityimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
- $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
-PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
-
$(PROJECT_INCLUDE)/rtems/posix/psignal.h: include/rtems/posix/psignal.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/psignal.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/psignal.h
diff --git a/cpukit/posix/src/mutex.c b/cpukit/posix/src/mutex.c
index 22b14c0..3e34dff 100644
--- a/cpukit/posix/src/mutex.c
+++ b/cpukit/posix/src/mutex.c
@@ -18,21 +18,25 @@
#include "config.h"
#endif
-#include <errno.h>
-#include <pthread.h>
#include <limits.h>
-#include <rtems/system.h>
#include <rtems/config.h>
#include <rtems/sysinit.h>
-#include <rtems/score/coremuteximpl.h>
-#include <rtems/score/watchdog.h>
#include <rtems/posix/muteximpl.h>
-#include <rtems/posix/priorityimpl.h>
+#include <rtems/score/objectimpl.h>
Objects_Information _POSIX_Mutex_Information;
-pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
+const pthread_mutexattr_t _POSIX_Mutex_Default_attributes = {
+#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
+ .type = PTHREAD_MUTEX_DEFAULT,
+#endif
+ .is_initialized = true,
+ .process_shared = PTHREAD_PROCESS_PRIVATE,
+ .prio_ceiling = INT_MAX,
+ .protocol = PTHREAD_PRIO_NONE,
+ .recursive = false
+};
/*
* _POSIX_Mutex_Manager_initialization
@@ -47,21 +51,6 @@ pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
static void _POSIX_Mutex_Manager_initialization(void)
{
- pthread_mutexattr_t *default_attr = &_POSIX_Mutex_Default_attributes;
-
- /*
- * Since the maximum priority is run-time configured, this
- * structure cannot be initialized statically.
- */
- default_attr->is_initialized = true;
- default_attr->process_shared = PTHREAD_PROCESS_PRIVATE;
- default_attr->prio_ceiling = POSIX_SCHEDULER_MAXIMUM_PRIORITY;
- default_attr->protocol = PTHREAD_PRIO_NONE;
- default_attr->recursive = false;
- #if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
- default_attr->type = PTHREAD_MUTEX_DEFAULT;
- #endif
-
/*
* Initialize the POSIX mutex object class information structure.
*/
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index 3459df7..0d4833e 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -36,6 +36,7 @@ int pthread_mutex_init(
POSIX_Mutex_Control *the_mutex;
const pthread_mutexattr_t *the_attr;
POSIX_Mutex_Protocol protocol;
+ const Scheduler_Control *scheduler;
Priority_Control priority;
if ( attr ) the_attr = attr;
@@ -105,11 +106,20 @@ int pthread_mutex_init(
#endif
if ( protocol == POSIX_MUTEX_PRIORITY_CEILING ) {
- if ( !_POSIX_Priority_Is_valid( the_attr->prio_ceiling ) ) {
+ int prio_ceiling;
+
+ scheduler = _Scheduler_Get_own( _Thread_Get_executing() );
+ prio_ceiling = the_attr->prio_ceiling;
+
+ if ( prio_ceiling == INT_MAX ) {
+ prio_ceiling = _POSIX_Priority_Get_maximum( scheduler );
+ }
+
+ if ( !_POSIX_Priority_Is_valid( prio_ceiling ) ) {
return EINVAL;
}
- priority = _POSIX_Priority_To_core( the_attr->prio_ceiling );
+ priority = _POSIX_Priority_To_core( prio_ceiling );
}
the_mutex = _POSIX_Mutex_Allocate();
diff --git a/cpukit/posix/src/psxpriorityisvalid.c b/cpukit/posix/src/psxpriorityisvalid.c
index 1bc7945..c883416 100644
--- a/cpukit/posix/src/psxpriorityisvalid.c
+++ b/cpukit/posix/src/psxpriorityisvalid.c
@@ -18,9 +18,17 @@
#include "config.h"
#endif
-#include <rtems/system.h>
#include <rtems/posix/priorityimpl.h>
+int _POSIX_Priority_Get_maximum( const Scheduler_Control *scheduler )
+{
+ if ( scheduler->maximum_priority < INT_MAX ) {
+ return (int) scheduler->maximum_priority - 1;
+ } else {
+ return INT_MAX;
+ }
+}
+
bool _POSIX_Priority_Is_valid(
int priority
)
diff --git a/cpukit/posix/src/sched_getprioritymax.c b/cpukit/posix/src/sched_getprioritymax.c
index 94114e3..5903f25 100644
--- a/cpukit/posix/src/sched_getprioritymax.c
+++ b/cpukit/posix/src/sched_getprioritymax.c
@@ -21,10 +21,9 @@
#endif
#include <sched.h>
-#include <errno.h>
-#include <rtems/system.h>
#include <rtems/seterr.h>
+#include <rtems/posix/priorityimpl.h>
#include <rtems/score/schedulerimpl.h>
int sched_get_priority_max(
@@ -45,10 +44,5 @@ int sched_get_priority_max(
}
scheduler = _Scheduler_Get_own( _Thread_Get_executing() );
-
- if ( scheduler->maximum_priority > INT_MAX ) {
- return INT_MAX;
- }
-
- return (int) scheduler->maximum_priority - 1;
+ return _POSIX_Priority_Get_maximum( scheduler );
}
More information about the vc
mailing list