source: rtems/cpukit/posix/src/pthreaddetach.c @ 1d572eba

5
Last change on this file since 1d572eba was 82c0836, checked in by Sebastian Huber <sebastian.huber@…>, on 03/28/17 at 05:51:16

posix: Fix pthread_detach() internal lock acquire

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Detaching a Thread
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Copyright (c) 2016 embedded brains GmbH.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <pthread.h>
24#include <errno.h>
25
26#include <rtems/score/threadimpl.h>
27
28/**
29 * 16.1.4 Detaching a Thread, P1003.1c/Draft 10, p. 149
30 */
31int pthread_detach( pthread_t thread )
32{
33  Thread_Control   *the_thread;
34  ISR_lock_Context  lock_context;
35  Per_CPU_Control  *cpu_self;
36
37  the_thread = _Thread_Get( thread, &lock_context );
38
39  if ( the_thread == NULL ) {
40    return ESRCH;
41  }
42
43  _Thread_State_acquire_critical( the_thread, &lock_context );
44
45  the_thread->Life.state |= THREAD_LIFE_DETACHED;
46  _Thread_Clear_state_locked( the_thread, STATES_WAITING_FOR_JOIN_AT_EXIT );
47
48  cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
49  _Thread_State_release( the_thread, &lock_context );
50  _Thread_Dispatch_enable( cpu_self );
51  return 0;
52}
Note: See TracBrowser for help on using the repository browser.