From e811d68705ccbd1829bc275f6933be996661149c Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 3 Jun 1996 21:06:51 +0000 Subject: deleted POSIX threads typedef masking Thread_Control added initial version of pthread_detach and pthread_join --- c/src/exec/posix/inline/pthread.inl | 17 +++-- c/src/exec/posix/inline/rtems/posix/pthread.inl | 17 +++-- c/src/exec/posix/src/pthread.c | 85 +++++++++++++++++++++++-- c/src/exec/posix/src/time.c | 2 +- 4 files changed, 96 insertions(+), 25 deletions(-) (limited to 'c') diff --git a/c/src/exec/posix/inline/pthread.inl b/c/src/exec/posix/inline/pthread.inl index 256372d326..2c2a2d5d7b 100644 --- a/c/src/exec/posix/inline/pthread.inl +++ b/c/src/exec/posix/inline/pthread.inl @@ -22,10 +22,9 @@ * _POSIX_Threads_Allocate */ -STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Allocate( void ) +STATIC INLINE Thread_Control *_POSIX_Threads_Allocate( void ) { - return (POSIX_Threads_Control *) - _Objects_Allocate( &_POSIX_Threads_Information ); + return (Thread_Control *) _Objects_Allocate( &_POSIX_Threads_Information ); } /*PAGE @@ -34,7 +33,7 @@ STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Allocate( void ) */ STATIC INLINE void _POSIX_Threads_Free ( - POSIX_Threads_Control *the_pthread + Thread_Control *the_pthread ) { _Objects_Free( &_POSIX_Threads_Information, &the_pthread->Object ); @@ -45,13 +44,13 @@ STATIC INLINE void _POSIX_Threads_Free ( * _POSIX_Threads_Get */ -STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Get ( - Objects_Id *id, +STATIC INLINE Thread_Control *_POSIX_Threads_Get ( + pthread_t id, Objects_Locations *location ) { - return (POSIX_Threads_Control *) - _Objects_Get( &_POSIX_Threads_Information, *id, location ); + return (Thread_Control *) + _Objects_Get( &_POSIX_Threads_Information, (Objects_Id)id, location ); } /*PAGE @@ -60,7 +59,7 @@ STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Get ( */ STATIC INLINE boolean _POSIX_Threads_Is_null ( - POSIX_Threads_Control *the_pthread + Thread_Control *the_pthread ) { return !the_pthread; diff --git a/c/src/exec/posix/inline/rtems/posix/pthread.inl b/c/src/exec/posix/inline/rtems/posix/pthread.inl index 256372d326..2c2a2d5d7b 100644 --- a/c/src/exec/posix/inline/rtems/posix/pthread.inl +++ b/c/src/exec/posix/inline/rtems/posix/pthread.inl @@ -22,10 +22,9 @@ * _POSIX_Threads_Allocate */ -STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Allocate( void ) +STATIC INLINE Thread_Control *_POSIX_Threads_Allocate( void ) { - return (POSIX_Threads_Control *) - _Objects_Allocate( &_POSIX_Threads_Information ); + return (Thread_Control *) _Objects_Allocate( &_POSIX_Threads_Information ); } /*PAGE @@ -34,7 +33,7 @@ STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Allocate( void ) */ STATIC INLINE void _POSIX_Threads_Free ( - POSIX_Threads_Control *the_pthread + Thread_Control *the_pthread ) { _Objects_Free( &_POSIX_Threads_Information, &the_pthread->Object ); @@ -45,13 +44,13 @@ STATIC INLINE void _POSIX_Threads_Free ( * _POSIX_Threads_Get */ -STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Get ( - Objects_Id *id, +STATIC INLINE Thread_Control *_POSIX_Threads_Get ( + pthread_t id, Objects_Locations *location ) { - return (POSIX_Threads_Control *) - _Objects_Get( &_POSIX_Threads_Information, *id, location ); + return (Thread_Control *) + _Objects_Get( &_POSIX_Threads_Information, (Objects_Id)id, location ); } /*PAGE @@ -60,7 +59,7 @@ STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Get ( */ STATIC INLINE boolean _POSIX_Threads_Is_null ( - POSIX_Threads_Control *the_pthread + Thread_Control *the_pthread ) { return !the_pthread; diff --git a/c/src/exec/posix/src/pthread.c b/c/src/exec/posix/src/pthread.c index 170a15adc3..23a9e606e0 100644 --- a/c/src/exec/posix/src/pthread.c +++ b/c/src/exec/posix/src/pthread.c @@ -178,7 +178,7 @@ void _POSIX_Threads_Manager_initialization( OBJECTS_POSIX_THREADS, FALSE, /* does not support global */ maximum_pthreads, - sizeof( POSIX_Threads_Control ), + sizeof( Thread_Control ), TRUE, 5, /* length is arbitrary for now */ TRUE /* this class is threads */ @@ -586,6 +586,7 @@ int pthread_create( boolean status; Thread_Control *the_thread; char *default_name = "psx"; + POSIX_API_Control *api; attrp = (attr) ? attr : &_POSIX_Threads_Default_attributes; @@ -683,6 +684,16 @@ int pthread_create( return EINVAL; } + /* + * finish initializing the per API structure + */ + + + api = the_thread->API_Extensions[ THREAD_API_POSIX ]; + + api->Attributes = *attrp; + api->detachstate = attr->detachstate; + status = _Thread_Start( the_thread, THREAD_START_POINTER, @@ -724,7 +735,28 @@ int pthread_join( void **value_ptr ) { - return POSIX_NOT_IMPLEMENTED(); + register Thread_Control *the_thread; + POSIX_API_Control *api; + Objects_Locations location; + + the_thread = _POSIX_Threads_Get( thread, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: + return ESRCH; + case OBJECTS_LOCAL: + api = the_thread->API_Extensions[ THREAD_API_POSIX ]; + + if ( api->detachstate == PTHREAD_CREATE_DETACHED ) + return EINVAL; + + /* XXX do something useful here */ + + return POSIX_NOT_IMPLEMENTED(); + break; + } + + return POSIX_BOTTOM_REACHED(); } /*PAGE @@ -736,7 +768,23 @@ int pthread_detach( pthread_t thread ) { - return POSIX_NOT_IMPLEMENTED(); + register Thread_Control *the_thread; + POSIX_API_Control *api; + Objects_Locations location; + + the_thread = _POSIX_Threads_Get( thread, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: + return ESRCH; + case OBJECTS_LOCAL: + + api = the_thread->API_Extensions[ THREAD_API_POSIX ]; + api->detachstate = PTHREAD_CREATE_DETACHED; + return 0; + } + + return POSIX_BOTTOM_REACHED(); } /*PAGE @@ -787,11 +835,36 @@ int pthread_equal( pthread_t t2 ) { -#ifdef RTEMS_DEBUG + Objects_Locations location; + /* XXX may want to do a "get" to make sure both are valid. */ /* XXX behavior is undefined if not valid pthread_t's */ -#endif - return _Objects_Are_ids_equal( t1, t1 ); + + /* + * Validate the first id and return 0 if it is not valid + */ + + (void) _POSIX_Threads_Get( t1, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: + return 0; + case OBJECTS_LOCAL: + break; + } + + /* + * Validate the second id and return 0 if it is not valid + */ + + (void) _POSIX_Threads_Get( t2, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: + return 0; + case OBJECTS_LOCAL: + return _Objects_Are_ids_equal( t1, t2 ); + } } /*PAGE diff --git a/c/src/exec/posix/src/time.c b/c/src/exec/posix/src/time.c index a3ea633e7d..1e33ed4fc1 100644 --- a/c/src/exec/posix/src/time.c +++ b/c/src/exec/posix/src/time.c @@ -188,7 +188,7 @@ int clock_gettime( #ifdef _POSIX_CPUTIME case CLOCK_PROCESS_CPUTIME: - /* could base this on _Watchdog_Ticks_since_boot -- must make set work though*/ + /* don't base this on _Watchdog_Ticks_since_boot--duration is too short*/ return POSIX_NOT_IMPLEMENTED(); break; #endif -- cgit v1.2.3