source: rtems/cpukit/posix/src/pthreadexit.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Thread Exit Shared Helper
5 * @ingroup POSIX_THREAD Thread API Extension
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2011.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <pthread.h>
22
23#include <rtems/posix/pthreadimpl.h>
24#include <rtems/score/apimutex.h>
25#include <rtems/score/threadimpl.h>
26#include <rtems/score/threadqimpl.h>
27
28void _POSIX_Thread_Exit(
29  Thread_Control *the_thread,
30  void           *value_ptr
31)
32{
33  Objects_Information  *the_information;
34  Thread_Control       *unblocked;
35  POSIX_API_Control    *api;
36
37  the_information = _Objects_Get_information_id( the_thread->Object.id );
38
39  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
40
41
42  /*
43   * The_information has to be non-NULL.  Otherwise, we couldn't be
44   * running in a thread of this API and class.
45   *
46   * NOTE: Lock and unlock in different order so we do not throw a
47   *       fatal error when locking the allocator mutex.  And after
48   *       we unlock, we want to defer the context switch until we
49   *       are ready to be switched out.  Otherwise, an ISR could
50   *       occur and preempt us out while we still hold the
51   *       allocator mutex.
52   */
53
54  _RTEMS_Lock_allocator();
55    _Thread_Disable_dispatch();
56
57      the_thread->Wait.return_argument = value_ptr;
58
59      /*
60       * Process join
61       */
62      if ( api->detachstate == PTHREAD_CREATE_JOINABLE ) {
63        unblocked = _Thread_queue_Dequeue( &api->Join_List );
64        if ( unblocked ) {
65          do {
66            *(void **)unblocked->Wait.return_argument = value_ptr;
67          } while ( (unblocked = _Thread_queue_Dequeue( &api->Join_List )) );
68        } else {
69          _Thread_Set_state(
70            the_thread,
71            STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT
72          );
73           /* FIXME: Lock order reversal */
74           _RTEMS_Unlock_allocator();
75          _Thread_Enable_dispatch();
76          /* now waiting for thread to arrive */
77          _RTEMS_Lock_allocator();
78          _Thread_Disable_dispatch();
79        }
80      }
81
82      /*
83       *  Now shut down the thread
84       */
85      _Thread_Close( the_information, the_thread );
86
87      _POSIX_Threads_Free( the_thread );
88
89     /* FIXME: Lock order reversal */
90    _RTEMS_Unlock_allocator();
91  _Thread_Enable_dispatch();
92}
93
94void pthread_exit(
95  void  *value_ptr
96)
97{
98  _POSIX_Thread_Exit( _Thread_Get_executing(), value_ptr );
99}
Note: See TracBrowser for help on using the repository browser.