summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/pthreaddetach.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-13 08:16:30 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-20 07:49:39 +0200
commit54550e048d3a49435912797d2024f80671e93267 (patch)
treebf49901187d98cf6a71975bdef7038d3ae0988c2 /cpukit/posix/src/pthreaddetach.c
parentscore: Simplify _Thread_Life_action_handler() (diff)
downloadrtems-54550e048d3a49435912797d2024f80671e93267.tar.bz2
posix: Rework pthread_join()
Rework pthread_join() to use _Thread_Join(). Close #2402. Update #2555. Update #2626. Close #2714.
Diffstat (limited to 'cpukit/posix/src/pthreaddetach.c')
-rw-r--r--cpukit/posix/src/pthreaddetach.c39
1 files changed, 17 insertions, 22 deletions
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 <pthread.h>
#include <errno.h>
-#include <rtems/posix/pthreadimpl.h>
#include <rtems/score/threadimpl.h>
/**
* 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;
}