summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2006-11-15 14:08:49 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2006-11-15 14:08:49 +0000
commit047d67ab257600533bc3a1047a2a54d287dcc2d2 (patch)
tree1fc509d0e86d7998aa162912bb9c3d01a7606fed /cpukit/posix/src
parentRegenerate. (diff)
downloadrtems-047d67ab257600533bc3a1047a2a54d287dcc2d2.tar.bz2
2006-11-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/src/termios.c, posix/Makefile.am, posix/preinstall.am, posix/include/rtems/posix/config.h, posix/include/rtems/posix/time.h, sapi/src/posixapi.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/corerwlock.h, score/include/rtems/score/threadq.h, score/src/corerwlockobtainread.c, score/src/threadqenqueue.c, score/src/threadqtimeout.c: Adding POSIX barriers, POSIX spinlocks, and partial implementation of POSIX rwlocks. * posix/include/rtems/posix/barrier.h, posix/include/rtems/posix/rwlock.h, posix/include/rtems/posix/spinlock.h, posix/inline/rtems/posix/barrier.inl, posix/inline/rtems/posix/rwlock.inl, posix/inline/rtems/posix/spinlock.inl, posix/src/barrierattrdestroy.c, posix/src/barrierattrgetpshared.c, posix/src/barrierattrinit.c, posix/src/barrierattrsetpshared.c, posix/src/pbarrier.c, posix/src/pbarrierdestroy.c, posix/src/pbarrierinit.c, posix/src/pbarriertranslatereturncode.c, posix/src/pbarrierwait.c, posix/src/prwlock.c, posix/src/prwlockdestroy.c, posix/src/prwlockinit.c, posix/src/prwlockrdlock.c, posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c, posix/src/prwlocktranslatereturncode.c, posix/src/prwlocktryrdlock.c, posix/src/prwlocktrywrlock.c, posix/src/prwlockunlock.c, posix/src/prwlockwrlock.c, posix/src/pspin.c, posix/src/pspindestroy.c, posix/src/pspininit.c, posix/src/pspinlock.c, posix/src/pspinlocktranslatereturncode.c, posix/src/pspintrylock.c, posix/src/pspinunlock.c, posix/src/rwlockattrdestroy.c, posix/src/rwlockattrgetpshared.c, posix/src/rwlockattrinit.c, posix/src/rwlockattrsetpshared.c: New files.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/barrierattrdestroy.c34
-rw-r--r--cpukit/posix/src/barrierattrgetpshared.c30
-rw-r--r--cpukit/posix/src/barrierattrinit.c29
-rw-r--r--cpukit/posix/src/barrierattrsetpshared.c37
-rw-r--r--cpukit/posix/src/pbarrier.c60
-rw-r--r--cpukit/posix/src/pbarrierdestroy.c71
-rw-r--r--cpukit/posix/src/pbarrierinit.c94
-rw-r--r--cpukit/posix/src/pbarriertranslatereturncode.c51
-rw-r--r--cpukit/posix/src/pbarrierwait.c68
-rw-r--r--cpukit/posix/src/prwlock.c48
-rw-r--r--cpukit/posix/src/prwlockdestroy.c73
-rw-r--r--cpukit/posix/src/prwlockinit.c90
-rw-r--r--cpukit/posix/src/prwlockrdlock.c71
-rw-r--r--cpukit/posix/src/prwlocktimedrdlock.c79
-rw-r--r--cpukit/posix/src/prwlocktimedwrlock.c79
-rw-r--r--cpukit/posix/src/prwlocktranslatereturncode.c51
-rw-r--r--cpukit/posix/src/prwlocktryrdlock.c72
-rw-r--r--cpukit/posix/src/prwlocktrywrlock.c71
-rw-r--r--cpukit/posix/src/prwlockunlock.c63
-rw-r--r--cpukit/posix/src/prwlockwrlock.c71
-rw-r--r--cpukit/posix/src/pspin.c60
-rw-r--r--cpukit/posix/src/pspindestroy.c71
-rw-r--r--cpukit/posix/src/pspininit.c80
-rw-r--r--cpukit/posix/src/pspinlock.c60
-rw-r--r--cpukit/posix/src/pspinlocktranslatereturncode.c53
-rw-r--r--cpukit/posix/src/pspintrylock.c60
-rw-r--r--cpukit/posix/src/pspinunlock.c60
-rw-r--r--cpukit/posix/src/rwlockattrdestroy.c34
-rw-r--r--cpukit/posix/src/rwlockattrgetpshared.c30
-rw-r--r--cpukit/posix/src/rwlockattrinit.c29
-rw-r--r--cpukit/posix/src/rwlockattrsetpshared.c37
31 files changed, 1816 insertions, 0 deletions
diff --git a/cpukit/posix/src/barrierattrdestroy.c b/cpukit/posix/src/barrierattrdestroy.c
new file mode 100644
index 0000000000..7b34b1c2ec
--- /dev/null
+++ b/cpukit/posix/src/barrierattrdestroy.c
@@ -0,0 +1,34 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * Barrier Initialization Attributes
+ */
+
+int pthread_barrierattr_destroy(
+ pthread_barrierattr_t *attr
+)
+{
+ if ( !attr || attr->is_initialized == FALSE )
+ return EINVAL;
+
+ attr->is_initialized = FALSE;
+ return 0;
+}
diff --git a/cpukit/posix/src/barrierattrgetpshared.c b/cpukit/posix/src/barrierattrgetpshared.c
new file mode 100644
index 0000000000..52fadb2d08
--- /dev/null
+++ b/cpukit/posix/src/barrierattrgetpshared.c
@@ -0,0 +1,30 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+/*PAGE
+ *
+ * Barrier Attributes Get Process Shared
+ */
+
+int pthread_barrierattr_getpshared(
+ const pthread_barrierattr_t *attr,
+ int *pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ *pshared = attr->process_shared;
+ return 0;
+}
diff --git a/cpukit/posix/src/barrierattrinit.c b/cpukit/posix/src/barrierattrinit.c
new file mode 100644
index 0000000000..ec7a036cf4
--- /dev/null
+++ b/cpukit/posix/src/barrierattrinit.c
@@ -0,0 +1,29 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+
+/*PAGE
+ *
+ * Barrier Attributes Initialization
+ */
+
+int pthread_barrierattr_init(
+ pthread_barrierattr_t *attr
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ attr->is_initialized = TRUE;
+ attr->process_shared = PTHREAD_PROCESS_PRIVATE;
+ return 0;
+}
diff --git a/cpukit/posix/src/barrierattrsetpshared.c b/cpukit/posix/src/barrierattrsetpshared.c
new file mode 100644
index 0000000000..e7d226ea1a
--- /dev/null
+++ b/cpukit/posix/src/barrierattrsetpshared.c
@@ -0,0 +1,37 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+/*PAGE
+ *
+ * Barrier Attributes Set Process Shared
+ */
+
+int pthread_barrierattr_setpshared(
+ pthread_barrierattr_t *attr,
+ int pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ switch ( pshared ) {
+ case PTHREAD_PROCESS_SHARED:
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->process_shared = pshared;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}
diff --git a/cpukit/posix/src/pbarrier.c b/cpukit/posix/src/pbarrier.c
new file mode 100644
index 0000000000..1b1c285b09
--- /dev/null
+++ b/cpukit/posix/src/pbarrier.c
@@ -0,0 +1,60 @@
+/*
+ * Barrier Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Barrier Manager.
+ *
+ * Directives provided are:
+ *
+ * + create a barrier
+ * + get an ID of a barrier
+ * + delete a barrier
+ * + acquire a barrier
+ * + release a barrier
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/**
+ * @brief _POSIX_Barrier_Manager_initialization
+ *
+ * Input parameters:
+ * maximum_barriers - maximum configured barriers
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_Barrier_Manager_initialization(
+ uint32_t maximum_barriers
+)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Barrier_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_BARRIERS, /* object class */
+ maximum_barriers, /* maximum objects of this class */
+ sizeof( POSIX_Barrier_Control ),/* size of this object's control block */
+ FALSE, /* TRUE if the name is a string */
+ 0 /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ FALSE, /* TRUE if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/pbarrierdestroy.c b/cpukit/posix/src/pbarrierdestroy.c
new file mode 100644
index 0000000000..ed48e78b55
--- /dev/null
+++ b/cpukit/posix/src/pbarrierdestroy.c
@@ -0,0 +1,71 @@
+/*
+ * POSIX Barrier Manager -- Destroy a Barrier
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/*
+ * pthread_barrier_destroy
+ *
+ * This directive allows a thread to delete a barrier specified by
+ * the barrier id. The barrier is freed back to the inactive
+ * barrier chain.
+ *
+ * Input parameters:
+ * barrier - barrier id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_barrier_destroy(
+ pthread_barrier_t *barrier
+)
+{
+ POSIX_Barrier_Control *the_barrier = NULL;
+ Objects_Locations location;
+
+ if ( !barrier )
+ return EINVAL;
+
+ the_barrier = _POSIX_Barrier_Get( barrier, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+ if ( the_barrier->Barrier.number_of_waiting_threads != 0 ) {
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ }
+
+ _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object );
+
+ _POSIX_Barrier_Free( the_barrier );
+
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/pbarrierinit.c b/cpukit/posix/src/pbarrierinit.c
new file mode 100644
index 0000000000..408964cfed
--- /dev/null
+++ b/cpukit/posix/src/pbarrierinit.c
@@ -0,0 +1,94 @@
+/*
+ * POSIX Barrier Manager -- Initialize a Barrier Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/*
+ * pthread_barrier_init
+ *
+ * This directive creates a barrier. A barrier id is returned.
+ *
+ * Input parameters:
+ * barrier - pointer to barrier id
+ * attr - barrier attributes
+ * count - number of threads before automatic release
+ *
+ * Output parameters:
+ * barrier - barrier id
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_barrier_init(
+ pthread_barrier_t *barrier,
+ const pthread_barrierattr_t *attr,
+ unsigned int count
+)
+{
+ POSIX_Barrier_Control *the_barrier;
+ CORE_barrier_Attributes the_attributes;
+
+
+ if ( !barrier )
+ return EINVAL;
+
+ if ( count == 0 )
+ return EINVAL;
+
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ switch ( attr->process_shared ) {
+ case PTHREAD_PROCESS_PRIVATE: /* only supported values */
+ break;
+ case PTHREAD_PROCESS_SHARED:
+ default:
+ return EINVAL;
+ }
+
+ the_attributes.discipline = CORE_BARRIER_AUTOMATIC_RELEASE;
+ the_attributes.maximum_count = count;
+
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_barrier = _POSIX_Barrier_Allocate();
+
+ if ( !the_barrier ) {
+ _Thread_Enable_dispatch();
+ return EAGAIN;
+ }
+
+ _CORE_barrier_Initialize( &the_barrier->Barrier, &the_attributes );
+
+ _Objects_Open(
+ &_POSIX_Barrier_Information,
+ &the_barrier->Object,
+ 0
+ );
+
+ *barrier = the_barrier->Object.id;
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/pbarriertranslatereturncode.c b/cpukit/posix/src/pbarriertranslatereturncode.c
new file mode 100644
index 0000000000..d7dc607bc3
--- /dev/null
+++ b/cpukit/posix/src/pbarriertranslatereturncode.c
@@ -0,0 +1,51 @@
+/*
+ * Barrier Manager -- Translate SuperCore Status
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/*
+ * _POSIX_Barrier_Translate_core_barrier_return_code
+ *
+ * Input parameters:
+ * the_barrier_status - barrier status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+static int _POSIX_Barrier_Return_codes[] = {
+ 0, /* CORE_BARRIER_STATUS_SUCCESSFUL */
+ PTHREAD_BARRIER_SERIAL_THREAD,
+ /* CORE_BARRIER_STATUS_AUTOMATICALLY_RELEASED */
+ -1, /* CORE_BARRIER_WAS_DELETED */
+ 0 /* CORE_BARRIER_TIMEOUT */
+};
+
+
+int _POSIX_Barrier_Translate_core_barrier_return_code(
+ CORE_barrier_Status the_barrier_status
+)
+{
+ if ( the_barrier_status <= CORE_BARRIER_TIMEOUT )
+ return _POSIX_Barrier_Return_codes[the_barrier_status];
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/pbarrierwait.c b/cpukit/posix/src/pbarrierwait.c
new file mode 100644
index 0000000000..8856274fe6
--- /dev/null
+++ b/cpukit/posix/src/pbarrierwait.c
@@ -0,0 +1,68 @@
+/*
+ * POSIX Barrier Manager -- Wait at a Barrier
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/barrier.h>
+
+/*
+ * pthread_barrier_wait
+ *
+ * This directive allows a thread to wait at a barrier.
+ *
+ * Input parameters:
+ * barrier - barrier id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * PTHREAD_BARRIER_SERIAL_THREAD - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_barrier_wait(
+ pthread_barrier_t *barrier
+)
+{
+ POSIX_Barrier_Control *the_barrier = NULL;
+ Objects_Locations location;
+
+ if ( !barrier )
+ return EINVAL;
+
+ the_barrier = _POSIX_Barrier_Get( barrier, &location );
+ switch ( location ) {
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+ _CORE_barrier_Wait(
+ &the_barrier->Barrier,
+ the_barrier->Object.id,
+ TRUE,
+ 0,
+ NULL
+ );
+ _Thread_Enable_dispatch();
+ return _POSIX_Barrier_Translate_core_barrier_return_code(
+ _Thread_Executing->Wait.return_code );
+
+ }
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlock.c b/cpukit/posix/src/prwlock.c
new file mode 100644
index 0000000000..37197a88b0
--- /dev/null
+++ b/cpukit/posix/src/prwlock.c
@@ -0,0 +1,48 @@
+/*
+ * RWLock Manager -- Initialization
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/**
+ * @brief _POSIX_RWLock_Manager_initialization
+ *
+ * Input parameters:
+ * maximum_rwlocks - maximum configured rwlocks
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_RWLock_Manager_initialization(
+ uint32_t maximum_rwlocks
+)
+{
+ _Objects_Initialize_information(
+ &_POSIX_RWLock_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_SPINLOCKS, /* object class */
+ maximum_rwlocks, /* maximum objects of this class */
+ sizeof( POSIX_RWLock_Control ), /* size of this object's control block */
+ FALSE, /* TRUE if the name is a string */
+ 0 /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ FALSE, /* TRUE if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/prwlockdestroy.c b/cpukit/posix/src/prwlockdestroy.c
new file mode 100644
index 0000000000..6ba858d1d9
--- /dev/null
+++ b/cpukit/posix/src/prwlockdestroy.c
@@ -0,0 +1,73 @@
+/*
+ * POSIX RWLock Manager -- Destroy a RWLock
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_destroy
+ *
+ * This directive allows a thread to delete a rwlock specified by
+ * the rwlock id. The rwlock is freed back to the inactive
+ * rwlock chain.
+ *
+ * Input parameters:
+ * rwlock - rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_destroy(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock = NULL;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+#if 0
+ if ( the_rwlock->RWLock.number_of_waiting_threads != 0 ) {
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ }
+#endif
+
+ _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
+
+ _POSIX_RWLock_Free( the_rwlock );
+
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlockinit.c b/cpukit/posix/src/prwlockinit.c
new file mode 100644
index 0000000000..6d6fe1a2c4
--- /dev/null
+++ b/cpukit/posix/src/prwlockinit.c
@@ -0,0 +1,90 @@
+/*
+ * POSIX RWLock Manager -- Destroy a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_init
+ *
+ * This directive creates a rwlock. A rwlock id is returned.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ * attr - rwlock attributes
+ *
+ * Output parameters:
+ * rwlock - rwlock id
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_init(
+ pthread_rwlock_t *rwlock,
+ const pthread_rwlockattr_t *attr
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ CORE_RWLock_Attributes the_attributes;
+
+
+ if ( !rwlock )
+ return EINVAL;
+
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ switch ( attr->process_shared ) {
+ case PTHREAD_PROCESS_PRIVATE: /* only supported values */
+ break;
+ case PTHREAD_PROCESS_SHARED:
+ default:
+ return EINVAL;
+ }
+
+/*
+ the_attributes.discipline = CORE_RWLOCK_AUTOMATIC_RELEASE;
+*/
+
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_rwlock = _POSIX_RWLock_Allocate();
+
+ if ( !the_rwlock ) {
+ _Thread_Enable_dispatch();
+ return EAGAIN;
+ }
+
+ _CORE_RWLock_Initialize( &the_rwlock->RWLock, &the_attributes );
+
+ _Objects_Open(
+ &_POSIX_RWLock_Information,
+ &the_rwlock->Object,
+ 0
+ );
+
+ *rwlock = the_rwlock->Object.id;
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/prwlockrdlock.c b/cpukit/posix/src/prwlockrdlock.c
new file mode 100644
index 0000000000..adc5130181
--- /dev/null
+++ b/cpukit/posix/src/prwlockrdlock.c
@@ -0,0 +1,71 @@
+/*
+ * POSIX RWLock Manager -- Obtain a Read Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_rdlock
+ *
+ * This directive attempts to obtain a read only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_rdlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_reading(
+ &the_rwlock->RWLock,
+ *rwlock,
+ TRUE, // we are willing to wait forever
+ 0,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlocktimedrdlock.c b/cpukit/posix/src/prwlocktimedrdlock.c
new file mode 100644
index 0000000000..2e9d578018
--- /dev/null
+++ b/cpukit/posix/src/prwlocktimedrdlock.c
@@ -0,0 +1,79 @@
+/*
+ * POSIX RWLock Manager -- Attempt to Obtain a Read Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+#include <rtems/posix/time.h>
+
+/*
+ * pthread_rwlock_timedrdlock
+ *
+ * This directive attempts to obtain a read only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_timedrdlock(
+ pthread_rwlock_t *rwlock,
+ const struct timespec *abstime
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+ Watchdog_Interval ticks;
+ int status;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ if ( !status )
+ return status;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_reading(
+ &the_rwlock->RWLock,
+ *rwlock,
+ TRUE, // we are willing to wait up to ticks
+ ticks,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlocktimedwrlock.c b/cpukit/posix/src/prwlocktimedwrlock.c
new file mode 100644
index 0000000000..5a5253ad02
--- /dev/null
+++ b/cpukit/posix/src/prwlocktimedwrlock.c
@@ -0,0 +1,79 @@
+/*
+ * POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+#include <rtems/posix/time.h>
+
+/*
+ * pthread_rwlock_timedwrlock
+ *
+ * This directive attempts to obtain a write only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_timedwrlock(
+ pthread_rwlock_t *rwlock,
+ const struct timespec *abstime
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+ int status;
+ Watchdog_Interval ticks;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
+ if ( !status )
+ return status;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_writing(
+ &the_rwlock->RWLock,
+ *rwlock,
+ TRUE, // we are willing to wait up to ticks
+ ticks,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlocktranslatereturncode.c b/cpukit/posix/src/prwlocktranslatereturncode.c
new file mode 100644
index 0000000000..5919643e4c
--- /dev/null
+++ b/cpukit/posix/src/prwlocktranslatereturncode.c
@@ -0,0 +1,51 @@
+/*
+ * RWLock Manager -- Translate SuperCore Status
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * _POSIX_RWLock_Translate_core_rwlock_return_code
+ *
+ * Input parameters:
+ * the_rwlock_status - rwlock status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+/* XXX fix me */
+static int _POSIX_RWLock_Return_codes[] = {
+ 0, /* CORE_RWLOCK_SUCCESSFUL */
+ EINVAL, /* CORE_RWLOCK_DELETED */
+ EBUSY, /* CORE_RWLOCK_UNAVAILABLE */
+ ETIMEDOUT, /* CORE_RWLOCK_TIMEOUT */
+};
+
+
+int _POSIX_RWLock_Translate_core_RWLock_return_code(
+ CORE_RWLock_Status the_rwlock_status
+)
+{
+ if ( the_rwlock_status <= CORE_RWLOCK_STATUS_LAST )
+ return _POSIX_RWLock_Return_codes[the_rwlock_status];
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlocktryrdlock.c b/cpukit/posix/src/prwlocktryrdlock.c
new file mode 100644
index 0000000000..9d988dd7f2
--- /dev/null
+++ b/cpukit/posix/src/prwlocktryrdlock.c
@@ -0,0 +1,72 @@
+/*
+ * POSIX RWLock Manager -- Attempt to Obtain a Read Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_tryrdlock
+ *
+ * This directive attempts to obtain a read only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_tryrdlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_reading(
+ &the_rwlock->RWLock,
+ *rwlock,
+ FALSE, // do not wait for the rwlock
+ 0,
+ NULL
+ );
+
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlocktrywrlock.c b/cpukit/posix/src/prwlocktrywrlock.c
new file mode 100644
index 0000000000..861a448447
--- /dev/null
+++ b/cpukit/posix/src/prwlocktrywrlock.c
@@ -0,0 +1,71 @@
+/*
+ * POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_trywrlock
+ *
+ * This directive attempts to obtain a Write only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_trywrlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_writing(
+ &the_rwlock->RWLock,
+ *rwlock,
+ FALSE, // we are not willing to wait
+ 0,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlockunlock.c b/cpukit/posix/src/prwlockunlock.c
new file mode 100644
index 0000000000..99f971ab17
--- /dev/null
+++ b/cpukit/posix/src/prwlockunlock.c
@@ -0,0 +1,63 @@
+/*
+ * POSIX RWLock Manager -- Release a lock held on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_unlock
+ *
+ * This directive attempts to release a lock on an RWLock.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_unlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+
+ /* XXX */
+
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/prwlockwrlock.c b/cpukit/posix/src/prwlockwrlock.c
new file mode 100644
index 0000000000..dfacd90a30
--- /dev/null
+++ b/cpukit/posix/src/prwlockwrlock.c
@@ -0,0 +1,71 @@
+/*
+ * POSIX RWLock Manager -- Obtain a Write Lock on a RWLock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/rwlock.h>
+
+/*
+ * pthread_rwlock_wrlock
+ *
+ * This directive attempts to obtain a write only lock on an rwlock instance.
+ *
+ * Input parameters:
+ * rwlock - pointer to rwlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_rwlock_wrlock(
+ pthread_rwlock_t *rwlock
+)
+{
+ POSIX_RWLock_Control *the_rwlock;
+ Objects_Locations location;
+
+ if ( !rwlock )
+ return EINVAL;
+
+ the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+
+ _CORE_RWLock_Obtain_for_writing(
+ &the_rwlock->RWLock,
+ *rwlock,
+ FALSE, /* do not timeout -- wait forever */
+ 0,
+ NULL
+ );
+
+ _Thread_Enable_dispatch();
+ return _POSIX_RWLock_Translate_core_RWLock_return_code(
+ (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
+ );
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/pspin.c b/cpukit/posix/src/pspin.c
new file mode 100644
index 0000000000..4a1379de27
--- /dev/null
+++ b/cpukit/posix/src/pspin.c
@@ -0,0 +1,60 @@
+/*
+ * Spinlock Manager
+ *
+ * DESCRIPTION:
+ *
+ * This package is the implementation of the Spinlock Manager.
+ *
+ * Directives provided are:
+ *
+ * + create a spinlock
+ * + get an ID of a spinlock
+ * + delete a spinlock
+ * + acquire a spinlock
+ * + release a spinlock
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/**
+ * @brief _POSIX_Spinlock_Manager_initialization
+ *
+ * Input parameters:
+ * maximum_spinlocks - maximum configured spinlocks
+ *
+ * Output parameters: NONE
+ */
+
+void _POSIX_Spinlock_Manager_initialization(
+ uint32_t maximum_spinlocks
+)
+{
+ _Objects_Initialize_information(
+ &_POSIX_Spinlock_Information, /* object information table */
+ OBJECTS_POSIX_API, /* object API */
+ OBJECTS_POSIX_SPINLOCKS, /* object class */
+ maximum_spinlocks, /* maximum objects of this class */
+ sizeof( POSIX_Spinlock_Control ),/* size of this object's control block */
+ FALSE, /* TRUE if the name is a string */
+ 0 /* maximum length of an object name */
+#if defined(RTEMS_MULTIPROCESSING)
+ ,
+ FALSE, /* TRUE if this is a global object class */
+ NULL /* Proxy extraction support callout */
+#endif
+ );
+}
diff --git a/cpukit/posix/src/pspindestroy.c b/cpukit/posix/src/pspindestroy.c
new file mode 100644
index 0000000000..fb5d8cc738
--- /dev/null
+++ b/cpukit/posix/src/pspindestroy.c
@@ -0,0 +1,71 @@
+/*
+ * POSIX Spinlock Manager -- Destroy a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spin_destroy
+ *
+ * This directive allows a thread to delete a spinlock specified by
+ * the spinlock id. The spinlock is freed back to the inactive
+ * spinlock chain.
+ *
+ * Input parameters:
+ * spinlock - spinlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_destroy(
+ pthread_spinlock_t *spinlock
+)
+{
+ POSIX_Spinlock_Control *the_spinlock = NULL;
+ Objects_Locations location;
+
+ if ( !spinlock )
+ return EINVAL;
+
+ the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
+ switch ( location ) {
+
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+ if ( _CORE_spinlock_Is_busy( &the_spinlock->Spinlock ) ) {
+ _Thread_Enable_dispatch();
+ return EBUSY;
+ }
+
+ _Objects_Close( &_POSIX_Spinlock_Information, &the_spinlock->Object );
+
+ _POSIX_Spinlock_Free( the_spinlock );
+
+ _Thread_Enable_dispatch();
+ return 0;
+ }
+
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/pspininit.c b/cpukit/posix/src/pspininit.c
new file mode 100644
index 0000000000..d7eb39a485
--- /dev/null
+++ b/cpukit/posix/src/pspininit.c
@@ -0,0 +1,80 @@
+/*
+ * POSIX Spinlock Manager -- Initialize a Spinlock Instance
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spinlock_init
+ *
+ * This directive creates a spinlock. A spinlock id is returned.
+ *
+ * Input parameters:
+ * spinlock - pointer to spinlock id
+ * pshared - is this spinlock shared between processes
+ *
+ * Output parameters:
+ * spinlock - spinlock id
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_init(
+ pthread_spinlock_t *spinlock,
+ int pshared
+)
+{
+ POSIX_Spinlock_Control *the_spinlock;
+ CORE_spinlock_Attributes attributes;
+
+
+ if ( !spinlock )
+ return EINVAL;
+
+ switch ( pshared ) {
+ case PTHREAD_PROCESS_PRIVATE: /* only supported values */
+ break;
+ case PTHREAD_PROCESS_SHARED:
+ default:
+ return EINVAL;
+ }
+
+ _Thread_Disable_dispatch(); /* prevents deletion */
+
+ the_spinlock = _POSIX_Spinlock_Allocate();
+
+ if ( !the_spinlock ) {
+ _Thread_Enable_dispatch();
+ return EAGAIN;
+ }
+
+ _CORE_spinlock_Initialize( &the_spinlock->Spinlock, &attributes );
+
+ _Objects_Open(
+ &_POSIX_Spinlock_Information,
+ &the_spinlock->Object,
+ 0
+ );
+
+ *spinlock = the_spinlock->Object.id;
+
+ _Thread_Enable_dispatch();
+ return 0;
+}
diff --git a/cpukit/posix/src/pspinlock.c b/cpukit/posix/src/pspinlock.c
new file mode 100644
index 0000000000..9888b43c32
--- /dev/null
+++ b/cpukit/posix/src/pspinlock.c
@@ -0,0 +1,60 @@
+/*
+ * POSIX Spinlock Manager -- Wait at a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spin_lock
+ *
+ * This directive allows a thread to wait at a spinlock.
+ *
+ * Input parameters:
+ * spinlock - spinlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_lock(
+ pthread_spinlock_t *spinlock
+)
+{
+ POSIX_Spinlock_Control *the_spinlock = NULL;
+ Objects_Locations location;
+ CORE_spinlock_Status status;
+
+ if ( !spinlock )
+ return EINVAL;
+
+ the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
+ switch ( location ) {
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+ status = _CORE_spinlock_Wait( &the_spinlock->Spinlock, TRUE, 0 );
+ _Thread_Enable_dispatch();
+ return _POSIX_Spinlock_Translate_core_spinlock_return_code( status );
+ }
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/pspinlocktranslatereturncode.c b/cpukit/posix/src/pspinlocktranslatereturncode.c
new file mode 100644
index 0000000000..0f72096c5a
--- /dev/null
+++ b/cpukit/posix/src/pspinlocktranslatereturncode.c
@@ -0,0 +1,53 @@
+/*
+ * Spinlock Manager -- Translate SuperCore Status
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * _POSIX_Spinlock_Translate_core_spinlock_return_code
+ *
+ * Input parameters:
+ * the_spinlock_status - spinlock status code to translate
+ *
+ * Output parameters:
+ * status code - translated POSIX status code
+ *
+ */
+
+/* XXX fix me */
+static int _POSIX_Spinlock_Return_codes[] = {
+ 0, /* CORE_SPINLOCK_SUCCESSFUL */
+ EDEADLK, /* CORE_SPINLOCK_HOLDER_RELOCKING */
+ -1, /* CORE_SPINLOCK_TIMEOUT */
+ EBUSY, /* CORE_SPINLOCK_IS_BUSY */
+ EBUSY, /* CORE_SPINLOCK_UNAVAILABLE */
+ 0 /* CORE_SPINLOCK_NOT_LOCKED */
+};
+
+
+int _POSIX_Spinlock_Translate_core_spinlock_return_code(
+ CORE_spinlock_Status the_spinlock_status
+)
+{
+ if ( the_spinlock_status <= CORE_SPINLOCK_STATUS_LAST )
+ return _POSIX_Spinlock_Return_codes[the_spinlock_status];
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/pspintrylock.c b/cpukit/posix/src/pspintrylock.c
new file mode 100644
index 0000000000..a77b0e2b21
--- /dev/null
+++ b/cpukit/posix/src/pspintrylock.c
@@ -0,0 +1,60 @@
+/*
+ * POSIX Spinlock Manager -- Wait at a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spin_trylock
+ *
+ * This directive allows a thread to poll an attempt at locking a spinlock.
+ *
+ * Input parameters:
+ * spinlock - spinlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_trylock(
+ pthread_spinlock_t *spinlock
+)
+{
+ POSIX_Spinlock_Control *the_spinlock = NULL;
+ Objects_Locations location;
+ CORE_spinlock_Status status;
+
+ if ( !spinlock )
+ return EINVAL;
+
+ the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
+ switch ( location ) {
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+ status = _CORE_spinlock_Wait( &the_spinlock->Spinlock, FALSE, 0 );
+ _Thread_Enable_dispatch();
+ return _POSIX_Spinlock_Translate_core_spinlock_return_code( status );
+ }
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/pspinunlock.c b/cpukit/posix/src/pspinunlock.c
new file mode 100644
index 0000000000..0af28ce56d
--- /dev/null
+++ b/cpukit/posix/src/pspinunlock.c
@@ -0,0 +1,60 @@
+/*
+ * POSIX Spinlock Manager -- Wait at a Spinlock
+ *
+ * COPYRIGHT (c) 1989-2006.
+ * 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 <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/spinlock.h>
+
+/*
+ * pthread_spin_unlock
+ *
+ * This directive allows a thread to wait at a spinlock.
+ *
+ * Input parameters:
+ * spinlock - spinlock id
+ *
+ * Output parameters:
+ * 0 - if successful
+ * error code - if unsuccessful
+ */
+
+int pthread_spin_unlock(
+ pthread_spinlock_t *spinlock
+)
+{
+ POSIX_Spinlock_Control *the_spinlock = NULL;
+ Objects_Locations location;
+ CORE_spinlock_Status status;
+
+ if ( !spinlock )
+ return EINVAL;
+
+ the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
+ switch ( location ) {
+ case OBJECTS_REMOTE:
+ case OBJECTS_ERROR:
+ return EINVAL;
+
+ case OBJECTS_LOCAL:
+ status = _CORE_spinlock_Release( &the_spinlock->Spinlock );
+ _Thread_Enable_dispatch();
+ return _POSIX_Spinlock_Translate_core_spinlock_return_code( status );
+ }
+ return POSIX_BOTTOM_REACHED();
+}
diff --git a/cpukit/posix/src/rwlockattrdestroy.c b/cpukit/posix/src/rwlockattrdestroy.c
new file mode 100644
index 0000000000..fc128ad610
--- /dev/null
+++ b/cpukit/posix/src/rwlockattrdestroy.c
@@ -0,0 +1,34 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/object.h>
+#include <rtems/score/states.h>
+#include <rtems/score/watchdog.h>
+#include <rtems/posix/cond.h>
+#include <rtems/posix/time.h>
+#include <rtems/posix/mutex.h>
+
+/*PAGE
+ *
+ * RWLock Initialization Attributes
+ */
+
+int pthread_rwlockattr_destroy(
+ pthread_rwlockattr_t *attr
+)
+{
+ if ( !attr || attr->is_initialized == FALSE )
+ return EINVAL;
+
+ attr->is_initialized = FALSE;
+ return 0;
+}
diff --git a/cpukit/posix/src/rwlockattrgetpshared.c b/cpukit/posix/src/rwlockattrgetpshared.c
new file mode 100644
index 0000000000..3f829a759d
--- /dev/null
+++ b/cpukit/posix/src/rwlockattrgetpshared.c
@@ -0,0 +1,30 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+/*PAGE
+ *
+ * RWLock Attributes Get Process Shared
+ */
+
+int pthread_rwlockattr_getpshared(
+ const pthread_rwlockattr_t *attr,
+ int *pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ *pshared = attr->process_shared;
+ return 0;
+}
diff --git a/cpukit/posix/src/rwlockattrinit.c b/cpukit/posix/src/rwlockattrinit.c
new file mode 100644
index 0000000000..f0ab2c5f5b
--- /dev/null
+++ b/cpukit/posix/src/rwlockattrinit.c
@@ -0,0 +1,29 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+
+/*PAGE
+ *
+ * RWLock Attributes Initialization
+ */
+
+int pthread_rwlockattr_init(
+ pthread_rwlockattr_t *attr
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ attr->is_initialized = TRUE;
+ attr->process_shared = PTHREAD_PROCESS_PRIVATE;
+ return 0;
+}
diff --git a/cpukit/posix/src/rwlockattrsetpshared.c b/cpukit/posix/src/rwlockattrsetpshared.c
new file mode 100644
index 0000000000..d122c5a0c1
--- /dev/null
+++ b/cpukit/posix/src/rwlockattrsetpshared.c
@@ -0,0 +1,37 @@
+/*
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+/*PAGE
+ *
+ * RWLock Attributes Set Process Shared
+ */
+
+int pthread_rwlockattr_setpshared(
+ pthread_rwlockattr_t *attr,
+ int pshared
+)
+{
+ if ( !attr )
+ return EINVAL;
+
+ if ( !attr->is_initialized )
+ return EINVAL;
+
+ switch ( pshared ) {
+ case PTHREAD_PROCESS_SHARED:
+ case PTHREAD_PROCESS_PRIVATE:
+ attr->process_shared = pshared;
+ return 0;
+
+ default:
+ return EINVAL;
+ }
+}