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.
This commit is contained in:
Glenn Humphrey
2007-11-06 19:52:36 +00:00
parent b214b1bab9
commit 8a8f5b263a
9 changed files with 113 additions and 23 deletions

View File

@@ -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,

View File

@@ -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 )
/*
* 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;
}
/*
* Now start error checking the attributes that we are going to use
*/
if ( !the_attr->is_initialized )
return EINVAL;
if ( !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;
}

View File

@@ -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 );

View File

@@ -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();

View File

@@ -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
);

View File

@@ -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 */

View File

@@ -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.
*/

View File

@@ -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 */
}

View File

@@ -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;
}