From 8cdf733f5003255ae7914f0a3b01f744f4add517 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 6 Jul 2009 14:46:36 +0000 Subject: 2009-07-06 Joel Sherrill * posix/Makefile.am, posix/src/mutex.c, posix/src/mutexinit.c: Add initial support for the pthread mutex type attribute added by UNIX98. It can be normal, recursive, errorcheck or default. * posix/src/mutexattrgettype.c, posix/src/mutexattrsettype.c: New files. --- cpukit/posix/src/mutex.c | 3 ++ cpukit/posix/src/mutexattrgettype.c | 39 ++++++++++++++++++++++ cpukit/posix/src/mutexattrsettype.c | 47 +++++++++++++++++++++++++++ cpukit/posix/src/mutexinit.c | 65 ++++++++++++++++++++++++------------- 4 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 cpukit/posix/src/mutexattrgettype.c create mode 100644 cpukit/posix/src/mutexattrsettype.c (limited to 'cpukit/posix/src') diff --git a/cpukit/posix/src/mutex.c b/cpukit/posix/src/mutex.c index ea71d6b277..6046b219f5 100644 --- a/cpukit/posix/src/mutex.c +++ b/cpukit/posix/src/mutex.c @@ -53,6 +53,9 @@ void _POSIX_Mutex_Manager_initialization(void) 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/mutexattrgettype.c b/cpukit/posix/src/mutexattrgettype.c new file mode 100644 index 0000000000..2d392967a3 --- /dev/null +++ b/cpukit/posix/src/mutexattrgettype.c @@ -0,0 +1,39 @@ +/* + * COPYRIGHT (c) 1989-2009. + * 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.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include + +#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES) +int pthread_mutexattr_gettype( + const pthread_mutexattr_t *attr, + int *type +) +{ + if ( !attr || !attr->is_initialized || !type ) + return EINVAL; + + *type = attr->type; + return 0; +} +#endif + diff --git a/cpukit/posix/src/mutexattrsettype.c b/cpukit/posix/src/mutexattrsettype.c new file mode 100644 index 0000000000..1cfb94d4d9 --- /dev/null +++ b/cpukit/posix/src/mutexattrsettype.c @@ -0,0 +1,47 @@ +/* + * COPYRIGHT (c) 1989-2009. + * 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.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include + +#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES) +int pthread_mutexattr_settype( + pthread_mutexattr_t *attr, + int type +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + switch ( type ) { + case PTHREAD_MUTEX_NORMAL: + case PTHREAD_MUTEX_RECURSIVE: + case PTHREAD_MUTEX_ERRORCHECK: + case PTHREAD_MUTEX_DEFAULT: + attr->type = type; + return 0; + + default: + return EINVAL; + } +} +#endif diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c index 353049a879..ca8a93011c 100644 --- a/cpukit/posix/src/mutexinit.c +++ b/cpukit/posix/src/mutexinit.c @@ -40,10 +40,6 @@ int pthread_mutex_init( CORE_mutex_Attributes *the_mutex_attr; const pthread_mutexattr_t *the_attr; CORE_mutex_Disciplines the_discipline; -#if 0 - register POSIX_Mutex_Control *mutex_in_use; - Objects_Locations location; -#endif if ( attr ) the_attr = attr; else the_attr = &_POSIX_Mutex_Default_attributes; @@ -70,27 +66,32 @@ int pthread_mutex_init( * RTEMS port of omniORB2 when this code was enabled. * * Joel Sherrill 14 May 1999 + * NOTE: Be careful to avoid infinite recursion on call to this + * routine in _POSIX_Mutex_Get. */ -#if 0 - /* avoid infinite recursion on call to this routine in _POSIX_Mutex_Get */ - - if ( *mutex != PTHREAD_MUTEX_INITIALIZER ) { - - /* EBUSY if *mutex is a valid id */ - - mutex_in_use = _POSIX_Mutex_Get( mutex, &location ); - switch ( location ) { - case OBJECTS_LOCAL: - _Thread_Enable_dispatch(); - return EBUSY; -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + #if 0 + { + POSIX_Mutex_Control *mutex_in_use; + Objects_Locations location; + + if ( *mutex != PTHREAD_MUTEX_INITIALIZER ) { + + /* EBUSY if *mutex is a valid id */ + + mutex_in_use = _POSIX_Mutex_Get( mutex, &location ); + switch ( location ) { + case OBJECTS_LOCAL: + _Thread_Enable_dispatch(); + return EBUSY; + #if defined(RTEMS_MULTIPROCESSING) + case OBJECTS_REMOTE: + #endif + case OBJECTS_ERROR: + break; + } } } -#endif + #endif if ( !the_attr->is_initialized ) return EINVAL; @@ -121,9 +122,29 @@ int pthread_mutex_init( return EINVAL; } + /* + * Validate the priority ceiling field -- should always be valid. + */ if ( !_POSIX_Priority_Is_valid( the_attr->prio_ceiling ) ) return EINVAL; +#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES) + /* + * Validate the mutex type and set appropriate SuperCore mutex + * attributes. + */ + switch ( the_attr->type ) { + case PTHREAD_MUTEX_NORMAL: + case PTHREAD_MUTEX_RECURSIVE: + case PTHREAD_MUTEX_ERRORCHECK: + case PTHREAD_MUTEX_DEFAULT: + break; + + default: + return EINVAL; + } +#endif + /* * Enter a dispatching critical section and begin to do the real work. */ -- cgit v1.2.3