diff options
Diffstat (limited to 'cpukit/posix/src/pthreadjoin.c')
-rw-r--r-- | cpukit/posix/src/pthreadjoin.c | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/cpukit/posix/src/pthreadjoin.c b/cpukit/posix/src/pthreadjoin.c index 2cb0903367..23a7749a81 100644 --- a/cpukit/posix/src/pthreadjoin.c +++ b/cpukit/posix/src/pthreadjoin.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -12,11 +14,28 @@ * 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 + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * - * 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. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifdef HAVE_CONFIG_H @@ -35,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 @@ -65,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; |