summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cpukit/ChangeLog7
-rw-r--r--cpukit/posix/Makefile.am13
-rw-r--r--cpukit/posix/src/mutex.c3
-rw-r--r--cpukit/posix/src/mutexattrgettype.c39
-rw-r--r--cpukit/posix/src/mutexattrsettype.c47
-rw-r--r--cpukit/posix/src/mutexinit.c65
6 files changed, 145 insertions, 29 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 95feb43712..3fdb5100f1 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,10 @@
+2009-07-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * 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.
+
2009-07-04 Joel Sherrill <joel.sherrill@OARcorp.com>
* rtems/src/taskinitusers.c: Restructure to eliminate dead check --
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index 8435779997..9bbfb67079 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -97,15 +97,14 @@ libposix_a_SOURCES += src/mqueue.c src/mqueueclose.c \
src/mqueueunlink.c
## MUTEX_C_FILES
-libposix_a_SOURCES += src/mutex.c src/mutexattrdestroy.c \
- src/mutexattrgetprioceiling.c src/mutexattrgetprotocol.c \
- src/mutexattrgetpshared.c src/mutexattrinit.c \
- src/mutexattrsetprioceiling.c src/mutexattrsetprotocol.c \
- src/mutexattrsetpshared.c src/mutexdestroy.c \
+libposix_a_SOURCES += src/mutexattrdestroy.c src/mutexattrgetprioceiling.c \
+ src/mutexattrgetprotocol.c src/mutexattrgetpshared.c \
+ src/mutexattrgettype.c src/mutexattrinit.c src/mutexattrsetprioceiling.c \
+ src/mutexattrsetprotocol.c src/mutexattrsetpshared.c \
+ src/mutexattrsettype.c src/mutex.c src/mutexdestroy.c src/mutexget.c \
src/mutexgetprioceiling.c src/mutexinit.c src/mutexlock.c \
src/mutexlocksupp.c src/mutexsetprioceiling.c src/mutextimedlock.c \
- src/mutextranslatereturncode.c src/mutextrylock.c src/mutexunlock.c \
- src/mutexget.c
+ src/mutextranslatereturncode.c src/mutextrylock.c src/mutexunlock.c
## PTHREAD_C_FILES
libposix_a_SOURCES += src/pthread.c src/pthreadsetcputime.c \
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 <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+#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 <errno.h>
+#include <pthread.h>
+
+#include <rtems/system.h>
+#include <rtems/score/coremutex.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/mutex.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+#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 <joel@OARcorp.com> 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.
*/