summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
diff options
context:
space:
mode:
authorGlenn Humphrey <glenn.humphrey@oarcorp.com>2007-11-06 19:52:36 +0000
committerGlenn Humphrey <glenn.humphrey@oarcorp.com>2007-11-06 19:52:36 +0000
commit8a8f5b263ae4a42b85a2d0c4a598b9702e04a57e (patch)
tree8ee935170b0b7bb403d9be6082cdaff91adb9063 /cpukit/posix
parent2007-11-06 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-8a8f5b263ae4a42b85a2d0c4a598b9702e04a57e.tar.bz2
2007-11-06 Glenn Humphrey <glenn.humphrey@OARcorp.com>
Miscellaneous changes made after a review against the POSIX spec. * posix/src/pbarrierinit.c, posix/src/prwlockinit.c: If the caller passes a NULL in the attributes parameter, default attributes are used. * posix/src/prwlockdestroy.c: If there is at least one thread waiting, do not allow deletion. * posix/src/prwlockwrlock.c: Corrected parameter passed to the core operation used to obtain a RWLock for writing. * posix/src/pspinlocktranslatereturncode.c, score/include/rtems/score/corespinlock.h, score/src/corespinlockrelease.c: If the current thread is not the holder of the lock, do not allow an unlock and return EPERM. * score/src/corerwlockobtainwrite.c: Corrected to use the operation for queueing with a timeout handler.
Diffstat (limited to 'cpukit/posix')
-rw-r--r--cpukit/posix/src/pbarrierinit.c40
-rw-r--r--cpukit/posix/src/prwlockdestroy.c11
-rw-r--r--cpukit/posix/src/prwlockinit.c36
-rw-r--r--cpukit/posix/src/prwlockwrlock.c2
-rw-r--r--cpukit/posix/src/pspinlocktranslatereturncode.c1
5 files changed, 68 insertions, 22 deletions
diff --git a/cpukit/posix/src/pbarrierinit.c b/cpukit/posix/src/pbarrierinit.c
index 408964cfed..816e695504 100644
--- a/cpukit/posix/src/pbarrierinit.c
+++ b/cpukit/posix/src/pbarrierinit.c
@@ -43,23 +43,37 @@ int pthread_barrier_init(
unsigned int count
)
{
- POSIX_Barrier_Control *the_barrier;
- CORE_barrier_Attributes the_attributes;
-
-
+ POSIX_Barrier_Control *the_barrier;
+ CORE_barrier_Attributes the_attributes;
+ pthread_barrierattr_t my_attr;
+ const pthread_barrierattr_t *the_attr;
+
+ /*
+ * Error check parameters
+ */
if ( !barrier )
return EINVAL;
if ( count == 0 )
return EINVAL;
- if ( !attr )
- return EINVAL;
+ /*
+ * If the user passed in NULL, use the default attributes
+ */
+ if ( attr ) {
+ the_attr = attr;
+ } else {
+ (void) pthread_barrierattr_init( &my_attr );
+ the_attr = &my_attr;
+ }
- if ( !attr->is_initialized )
+ /*
+ * Now start error checking the attributes that we are going to use
+ */
+ if ( !the_attr->is_initialized )
return EINVAL;
- switch ( attr->process_shared ) {
+ switch ( the_attr->process_shared ) {
case PTHREAD_PROCESS_PRIVATE: /* only supported values */
break;
case PTHREAD_PROCESS_SHARED:
@@ -67,9 +81,15 @@ int pthread_barrier_init(
return EINVAL;
}
+ /*
+ * Convert from POSIX attributes to Core Barrier attributes
+ */
the_attributes.discipline = CORE_BARRIER_AUTOMATIC_RELEASE;
the_attributes.maximum_count = count;
+ /*
+ * Enter dispatching critical section to allocate and initialize barrier
+ */
_Thread_Disable_dispatch(); /* prevents deletion */
the_barrier = _POSIX_Barrier_Allocate();
@@ -87,8 +107,10 @@ int pthread_barrier_init(
0
);
+ /*
+ * Exit the critical section and return the user an operational barrier
+ */
*barrier = the_barrier->Object.id;
-
_Thread_Enable_dispatch();
return 0;
}
diff --git a/cpukit/posix/src/prwlockdestroy.c b/cpukit/posix/src/prwlockdestroy.c
index 67dac7571a..dc81393d8d 100644
--- a/cpukit/posix/src/prwlockdestroy.c
+++ b/cpukit/posix/src/prwlockdestroy.c
@@ -56,12 +56,17 @@ int pthread_rwlock_destroy(
return EINVAL;
case OBJECTS_LOCAL:
-#if 0
- if ( the_rwlock->RWLock.number_of_waiting_threads != 0 ) {
+ /*
+ * If there is at least one thread waiting, then do not delete it.
+ */
+ if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) {
_Thread_Enable_dispatch();
return EBUSY;
}
-#endif
+
+ /*
+ * POSIX doesn't require behavior when it is locked.
+ */
_Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
diff --git a/cpukit/posix/src/prwlockinit.c b/cpukit/posix/src/prwlockinit.c
index 6d6fe1a2c4..7149a68e09 100644
--- a/cpukit/posix/src/prwlockinit.c
+++ b/cpukit/posix/src/prwlockinit.c
@@ -41,16 +41,30 @@ int pthread_rwlock_init(
const pthread_rwlockattr_t *attr
)
{
- POSIX_RWLock_Control *the_rwlock;
- CORE_RWLock_Attributes the_attributes;
-
-
+ POSIX_RWLock_Control *the_rwlock;
+ CORE_RWLock_Attributes the_attributes;
+ pthread_rwlockattr_t default_attr;
+ const pthread_rwlockattr_t *the_attr;
+
+ /*
+ * Error check parameters
+ */
if ( !rwlock )
return EINVAL;
- if ( !attr )
- return EINVAL;
+ /*
+ * If the user passed in NULL, use the default attributes
+ */
+ if ( attr ) {
+ the_attr = attr;
+ } else {
+ (void) pthread_rwlockattr_init( &default_attr );
+ the_attr = &default_attr;
+ }
+ /*
+ * Now start error checking the attributes that we are going to use
+ */
if ( !attr->is_initialized )
return EINVAL;
@@ -62,10 +76,14 @@ int pthread_rwlock_init(
return EINVAL;
}
-/*
- the_attributes.discipline = CORE_RWLOCK_AUTOMATIC_RELEASE;
-*/
+ /*
+ * Convert from POSIX attributes to Core RWLock attributes
+ */
+ /* Currently there are no core rwlock attributes */
+ /*
+ * Enter dispatching critical section to allocate and initialize RWLock
+ */
_Thread_Disable_dispatch(); /* prevents deletion */
the_rwlock = _POSIX_RWLock_Allocate();
diff --git a/cpukit/posix/src/prwlockwrlock.c b/cpukit/posix/src/prwlockwrlock.c
index 6539e617a1..47b13f5647 100644
--- a/cpukit/posix/src/prwlockwrlock.c
+++ b/cpukit/posix/src/prwlockwrlock.c
@@ -58,7 +58,7 @@ int pthread_rwlock_wrlock(
_CORE_RWLock_Obtain_for_writing(
&the_rwlock->RWLock,
*rwlock,
- FALSE, /* do not timeout -- wait forever */
+ TRUE, /* do not timeout -- wait forever */
0,
NULL
);
diff --git a/cpukit/posix/src/pspinlocktranslatereturncode.c b/cpukit/posix/src/pspinlocktranslatereturncode.c
index 0f72096c5a..3b45d72e6b 100644
--- a/cpukit/posix/src/pspinlocktranslatereturncode.c
+++ b/cpukit/posix/src/pspinlocktranslatereturncode.c
@@ -36,6 +36,7 @@
static int _POSIX_Spinlock_Return_codes[] = {
0, /* CORE_SPINLOCK_SUCCESSFUL */
EDEADLK, /* CORE_SPINLOCK_HOLDER_RELOCKING */
+ EPERM, /* CORE_SPINLOCK_NOT_HOLDER */
-1, /* CORE_SPINLOCK_TIMEOUT */
EBUSY, /* CORE_SPINLOCK_IS_BUSY */
EBUSY, /* CORE_SPINLOCK_UNAVAILABLE */