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.
This commit is contained in:
Sebastian Huber
2016-06-14 11:45:22 +02:00
parent ce6e9ec22f
commit 2df7fcff88
8 changed files with 50 additions and 39 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -59,6 +59,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.
*

View File

@@ -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

View File

@@ -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.
*/

View File

@@ -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();

View File

@@ -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
)

View File

@@ -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 );
}