Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision 70a4809f8413204e8a93d4384b239f3c73278eb2)
+++ cpukit/ChangeLog	(revision 8cdf733f5003255ae7914f0a3b01f744f4add517)
@@ -1,2 +1,9 @@
+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>
 
Index: cpukit/posix/Makefile.am
===================================================================
--- cpukit/posix/Makefile.am	(revision 70a4809f8413204e8a93d4384b239f3c73278eb2)
+++ cpukit/posix/Makefile.am	(revision 8cdf733f5003255ae7914f0a3b01f744f4add517)
@@ -98,13 +98,12 @@
 
 ## 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
Index: cpukit/posix/src/mutex.c
===================================================================
--- cpukit/posix/src/mutex.c	(revision 70a4809f8413204e8a93d4384b239f3c73278eb2)
+++ cpukit/posix/src/mutex.c	(revision 8cdf733f5003255ae7914f0a3b01f744f4add517)
@@ -54,4 +54,7 @@
   default_attr->protocol       = PTHREAD_PRIO_NONE;
   default_attr->recursive      = false;
+  #if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
+    default_attr->type         = PTHREAD_MUTEX_DEFAULT;
+  #endif
 
   /*
Index: cpukit/posix/src/mutexattrgettype.c
===================================================================
--- cpukit/posix/src/mutexattrgettype.c	(revision 8cdf733f5003255ae7914f0a3b01f744f4add517)
+++ cpukit/posix/src/mutexattrgettype.c	(revision 8cdf733f5003255ae7914f0a3b01f744f4add517)
@@ -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
+
Index: cpukit/posix/src/mutexattrsettype.c
===================================================================
--- cpukit/posix/src/mutexattrsettype.c	(revision 8cdf733f5003255ae7914f0a3b01f744f4add517)
+++ cpukit/posix/src/mutexattrsettype.c	(revision 8cdf733f5003255ae7914f0a3b01f744f4add517)
@@ -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
Index: cpukit/posix/src/mutexinit.c
===================================================================
--- cpukit/posix/src/mutexinit.c	(revision 70a4809f8413204e8a93d4384b239f3c73278eb2)
+++ cpukit/posix/src/mutexinit.c	(revision 8cdf733f5003255ae7914f0a3b01f744f4add517)
@@ -41,8 +41,4 @@
   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;
@@ -71,25 +67,30 @@
    *
    *  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 0
+  {
+    POSIX_Mutex_Control *mutex_in_use;
+    Objects_Locations    location;
 
-  if ( *mutex != PTHREAD_MUTEX_INITIALIZER ) {
+    if ( *mutex != PTHREAD_MUTEX_INITIALIZER ) {
 
-    /* EBUSY if *mutex is a valid id */
+      /* 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;
+      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 )
@@ -122,6 +123,26 @@
   }
 
+  /*
+   *  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
 
   /*
