source: rtems/cpukit/posix/src/pthreadjoin.c

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup POSIXAPI
7 *
8 * @brief Suspends Execution of Calling Thread until Target Thread Terminates
9 */
10
11/*
12 *  16.1.3 Wait for Thread Termination, P1003.1c/Draft 10, p. 147
13 *
14 *  COPYRIGHT (c) 1989-2014.
15 *  On-Line Applications Research Corporation (OAR).
16 *
17 *  Copyright (c) 2016 embedded brains GmbH & Co. KG
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 * 1. Redistributions of source code must retain the above copyright
23 *    notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 *    notice, this list of conditions and the following disclaimer in the
26 *    documentation and/or other materials provided with the distribution.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifdef HAVE_CONFIG_H
42#include "config.h"
43#endif
44
45#include <pthread.h>
46#include <errno.h>
47
48#include <rtems/posix/threadsup.h>
49#include <rtems/posix/posixapi.h>
50#include <rtems/score/threadimpl.h>
51#include <rtems/score/statesimpl.h>
52
53static int _POSIX_Threads_Join( pthread_t thread, void **value_ptr )
54{
55  Thread_Control       *the_thread;
56  Thread_queue_Context  queue_context;
57  Thread_Control       *executing;
58  Status_Control        status;
59
60  _Thread_queue_Context_initialize( &queue_context );
61  the_thread = _Thread_Get( thread, &queue_context.Lock_context.Lock_context );
62
63  if ( the_thread == NULL ) {
64    return ESRCH;
65  }
66
67  _Thread_State_acquire_critical(
68    the_thread,
69    &queue_context.Lock_context.Lock_context
70  );
71
72  if ( !_Thread_Is_joinable( the_thread ) ) {
73    _Thread_State_release( the_thread, &queue_context.Lock_context.Lock_context );
74    return EINVAL;
75  }
76
77  executing = _Thread_Executing;
78  status = _Thread_Join(
79    the_thread,
80    STATES_INTERRUPTIBLE_BY_SIGNAL | STATES_WAITING_FOR_JOIN,
81    executing,
82    &queue_context
83  );
84
85  if ( status != STATUS_SUCCESSFUL ) {
86    return _POSIX_Get_error( status );
87  }
88
89  if ( value_ptr != NULL ) {
90    *value_ptr = executing->Wait.return_argument;
91  }
92
93  return 0;
94}
95
96int pthread_join( pthread_t thread, void **value_ptr )
97{
98  int error;
99
100  do {
101    error = _POSIX_Threads_Join( thread, value_ptr );
102  } while ( error == EINTR );
103
104  return error;
105}
Note: See TracBrowser for help on using the repository browser.