summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-14 11:45:22 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-22 14:00:27 +0200
commit2df7fcff883856cd2fa8a56e9c509a0674bfb01a (patch)
treec277f34f4cac80f4a629c4438f51b6dd66102625 /cpukit/posix/src
parentce6e9ec22f3a4ba976c9de2b7b0fbe646f1b36de (diff)
downloadrtems-2df7fcff883856cd2fa8a56e9c509a0674bfb01a.tar.bz2
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.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/mutex.c33
-rw-r--r--cpukit/posix/src/mutexinit.c14
-rw-r--r--cpukit/posix/src/psxpriorityisvalid.c10
-rw-r--r--cpukit/posix/src/sched_getprioritymax.c10
4 files changed, 34 insertions, 33 deletions
diff --git a/cpukit/posix/src/mutex.c b/cpukit/posix/src/mutex.c
index 22b14c0001..3e34dffb3d 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 3459df77dd..0d4833ed90 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 1bc7945136..c883416c86 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 94114e3b84..5903f25d59 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 );
}