summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorGlenn Humphrey <glenn.humphrey@oarcorp.com>2007-11-06 19:54:22 +0000
committerGlenn Humphrey <glenn.humphrey@oarcorp.com>2007-11-06 19:54:22 +0000
commit22112254389fc40e8d4431554c4c64651a5c4b5c (patch)
tree10fdcd2d6473cfbc4ae1aba6afa7e7eb82fedbb5 /cpukit
parentRegenerate. (diff)
downloadrtems-22112254389fc40e8d4431554c4c64651a5c4b5c.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')
-rw-r--r--cpukit/ChangeLog16
-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
-rw-r--r--cpukit/score/include/rtems/score/corespinlock.h4
-rw-r--r--cpukit/score/src/corerwlockobtainwrite.c7
-rw-r--r--cpukit/score/src/corespinlockrelease.c21
9 files changed, 114 insertions, 24 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 6e8a73f5ea..6e036ba9e4 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,19 @@
+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.
+
2007-11-02 Joel Sherrill <joel.sherrill@OARcorp.com>
* score/cpu/sparc/cpu.c, score/cpu/sparc/rtems/score/cpu.h,
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 6ba858d1d9..d55fd1f206 100644
--- a/cpukit/posix/src/prwlockdestroy.c
+++ b/cpukit/posix/src/prwlockdestroy.c
@@ -54,12 +54,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 dfacd90a30..127a6b0a23 100644
--- a/cpukit/posix/src/prwlockwrlock.c
+++ b/cpukit/posix/src/prwlockwrlock.c
@@ -56,7 +56,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 */
diff --git a/cpukit/score/include/rtems/score/corespinlock.h b/cpukit/score/include/rtems/score/corespinlock.h
index dc559b2a7c..58012c8add 100644
--- a/cpukit/score/include/rtems/score/corespinlock.h
+++ b/cpukit/score/include/rtems/score/corespinlock.h
@@ -45,6 +45,10 @@ typedef enum {
* An attempt to relock it will result in deadlock.
*/
CORE_SPINLOCK_HOLDER_RELOCKING,
+ /** This status indicates that the current thread is attempting to unlock a
+ * spinlock that is held by another thread.
+ */
+ CORE_SPINLOCK_NOT_HOLDER,
/** This status indicates that a thread reached the limit of time it
* was willing to wait on the spin lock.
*/
diff --git a/cpukit/score/src/corerwlockobtainwrite.c b/cpukit/score/src/corerwlockobtainwrite.c
index 02e7906249..a1535b786f 100644
--- a/cpukit/score/src/corerwlockobtainwrite.c
+++ b/cpukit/score/src/corerwlockobtainwrite.c
@@ -87,7 +87,12 @@ void _CORE_RWLock_Obtain_for_writing(
executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
_ISR_Enable( level );
- _Thread_queue_Enqueue( &the_rwlock->Wait_queue, timeout );
+ _Thread_queue_Enqueue_with_handler(
+ &the_rwlock->Wait_queue,
+ timeout,
+ _CORE_RWLock_Timeout
+ );
+
/* return to API level so it can dispatch and we block */
}
diff --git a/cpukit/score/src/corespinlockrelease.c b/cpukit/score/src/corespinlockrelease.c
index 05aec32c4c..46aa7c1105 100644
--- a/cpukit/score/src/corespinlockrelease.c
+++ b/cpukit/score/src/corespinlockrelease.c
@@ -30,7 +30,10 @@
* Input parameters:
* the_spinlock - the spinlock control block to initialize
*
- * Output parameters: NONE
+ * Output parameters:
+ * CORE_SPINLOCK_SUCCESSFUL - if successful
+ * error code - if unsuccessful
+ *
*/
CORE_spinlock_Status _CORE_spinlock_Release(
@@ -40,14 +43,30 @@ CORE_spinlock_Status _CORE_spinlock_Release(
ISR_Level level;
_ISR_Disable( level );
+
+ /*
+ * It must locked before it can be unlocked.
+ */
if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) {
_ISR_Enable( level );
return CORE_SPINLOCK_NOT_LOCKED;
}
+
+ /*
+ * It must locked by the current thread before it can be unlocked.
+ */
+ if ( the_spinlock->holder != _Thread_Executing->Object.id ) {
+ _ISR_Enable( level );
+ return CORE_SPINLOCK_NOT_HOLDER;
+ }
+ /*
+ * Let it be unlocked.
+ */
the_spinlock->users -= 1;
the_spinlock->lock = CORE_SPINLOCK_UNLOCKED;
the_spinlock->holder = 0;
+
_ISR_Enable( level );
return CORE_SPINLOCK_SUCCESSFUL;
}