summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/pthreadjoin.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/posix/src/pthreadjoin.c')
-rw-r--r--cpukit/posix/src/pthreadjoin.c49
1 files changed, 13 insertions, 36 deletions
diff --git a/cpukit/posix/src/pthreadjoin.c b/cpukit/posix/src/pthreadjoin.c
index 84ff15ceec..23a7749a81 100644
--- a/cpukit/posix/src/pthreadjoin.c
+++ b/cpukit/posix/src/pthreadjoin.c
@@ -14,7 +14,7 @@
* COPYRIGHT (c) 1989-2014.
* On-Line Applications Research Corporation (OAR).
*
- * Copyright (c) 2016 embedded brains GmbH.
+ * Copyright (c) 2016 embedded brains GmbH & Co. KG
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -54,26 +54,16 @@ static int _POSIX_Threads_Join( pthread_t thread, void **value_ptr )
{
Thread_Control *the_thread;
Thread_queue_Context queue_context;
- Per_CPU_Control *cpu_self;
Thread_Control *executing;
- void *value;
+ Status_Control status;
_Thread_queue_Context_initialize( &queue_context );
- _Thread_queue_Context_set_enqueue_do_nothing_extra( &queue_context );
the_thread = _Thread_Get( thread, &queue_context.Lock_context.Lock_context );
if ( the_thread == NULL ) {
return ESRCH;
}
- cpu_self = _Per_CPU_Get();
- executing = _Per_CPU_Get_executing( cpu_self );
-
- if ( executing == the_thread ) {
- _ISR_lock_ISR_enable( &queue_context.Lock_context.Lock_context );
- return EDEADLK;
- }
-
_Thread_State_acquire_critical(
the_thread,
&queue_context.Lock_context.Lock_context
@@ -84,33 +74,20 @@ static int _POSIX_Threads_Join( pthread_t thread, void **value_ptr )
return EINVAL;
}
- if ( _States_Is_waiting_for_join_at_exit( the_thread->current_state ) ) {
- value = the_thread->Life.exit_value;
- _Thread_Clear_state_locked( the_thread, STATES_WAITING_FOR_JOIN_AT_EXIT );
- _Thread_Dispatch_disable_with_CPU(
- cpu_self,
- &queue_context.Lock_context.Lock_context
- );
- _Thread_State_release( the_thread, &queue_context.Lock_context.Lock_context );
- _Thread_Dispatch_direct( cpu_self );
- } else {
- _Thread_Join(
- the_thread,
- STATES_INTERRUPTIBLE_BY_SIGNAL | STATES_WAITING_FOR_JOIN,
- executing,
- &queue_context
- );
-
- if ( _POSIX_Get_error_after_wait( executing ) != 0 ) {
- _Assert( _POSIX_Get_error_after_wait( executing ) == EINTR );
- return EINTR;
- }
-
- value = executing->Wait.return_argument;
+ executing = _Thread_Executing;
+ status = _Thread_Join(
+ the_thread,
+ STATES_INTERRUPTIBLE_BY_SIGNAL | STATES_WAITING_FOR_JOIN,
+ executing,
+ &queue_context
+ );
+
+ if ( status != STATUS_SUCCESSFUL ) {
+ return _POSIX_Get_error( status );
}
if ( value_ptr != NULL ) {
- *value_ptr = value;
+ *value_ptr = executing->Wait.return_argument;
}
return 0;