From 54550e048d3a49435912797d2024f80671e93267 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 13 May 2016 08:16:30 +0200 Subject: posix: Rework pthread_join() Rework pthread_join() to use _Thread_Join(). Close #2402. Update #2555. Update #2626. Close #2714. --- cpukit/posix/src/pthreaddetach.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'cpukit/posix/src/pthreaddetach.c') diff --git a/cpukit/posix/src/pthreaddetach.c b/cpukit/posix/src/pthreaddetach.c index d8c6afb06e..fe2a590252 100644 --- a/cpukit/posix/src/pthreaddetach.c +++ b/cpukit/posix/src/pthreaddetach.c @@ -9,6 +9,8 @@ * COPYRIGHT (c) 1989-2014. * On-Line Applications Research Corporation (OAR). * + * Copyright (c) 2016 embedded brains GmbH. + * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.org/license/LICENSE. @@ -21,37 +23,30 @@ #include #include -#include #include /** * 16.1.4 Detaching a Thread, P1003.1c/Draft 10, p. 149 */ -int pthread_detach( - pthread_t thread -) +int pthread_detach( pthread_t thread ) { - Thread_Control *the_thread; - POSIX_API_Control *api; - Objects_Locations location; + Thread_Control *the_thread; + ISR_lock_Context lock_context; + Per_CPU_Control *cpu_self; - the_thread = _Thread_Get( thread, &location ); - switch ( location ) { + the_thread = _Thread_Get_interrupt_disable( thread, &lock_context ); - case OBJECTS_LOCAL: + if ( the_thread == NULL ) { + return ESRCH; + } - api = the_thread->API_Extensions[ THREAD_API_POSIX ]; - api->detachstate = PTHREAD_CREATE_DETACHED; - api->Attributes.detachstate = PTHREAD_CREATE_DETACHED; - _Objects_Put( &the_thread->Object ); - return 0; + _Thread_State_acquire( the_thread, &lock_context ); -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; - } + the_thread->Life.state |= THREAD_LIFE_DETACHED; + _Thread_Clear_state_locked( the_thread, STATES_WAITING_FOR_JOIN_AT_EXIT ); - return ESRCH; + cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); + _Thread_State_release( the_thread, &lock_context ); + _Thread_Dispatch_enable( cpu_self ); + return 0; } -- cgit v1.2.3