1*062c5bc4SJason Schmidlapp /*
2*062c5bc4SJason Schmidlapp * pthread_exit.c
3*062c5bc4SJason Schmidlapp *
4*062c5bc4SJason Schmidlapp * Description:
5*062c5bc4SJason Schmidlapp * This translation unit implements routines associated with exiting from
6*062c5bc4SJason Schmidlapp * a thread.
7*062c5bc4SJason Schmidlapp *
8*062c5bc4SJason Schmidlapp * --------------------------------------------------------------------------
9*062c5bc4SJason Schmidlapp *
10*062c5bc4SJason Schmidlapp * Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
11*062c5bc4SJason Schmidlapp * Copyright(C) 2008 Jason Schmidlapp
12*062c5bc4SJason Schmidlapp *
13*062c5bc4SJason Schmidlapp * Contact Email: jschmidlapp@users.sourceforge.net
14*062c5bc4SJason Schmidlapp *
15*062c5bc4SJason Schmidlapp *
16*062c5bc4SJason Schmidlapp * Based upon Pthreads-win32 - POSIX Threads Library for Win32
17*062c5bc4SJason Schmidlapp * Copyright(C) 1998 John E. Bossom
18*062c5bc4SJason Schmidlapp * Copyright(C) 1999,2005 Pthreads-win32 contributors
19*062c5bc4SJason Schmidlapp *
20*062c5bc4SJason Schmidlapp * Contact Email: rpj@callisto.canberra.edu.au
21*062c5bc4SJason Schmidlapp *
22*062c5bc4SJason Schmidlapp * The original list of contributors to the Pthreads-win32 project
23*062c5bc4SJason Schmidlapp * is contained in the file CONTRIBUTORS.ptw32 included with the
24*062c5bc4SJason Schmidlapp * source code distribution. The list can also be seen at the
25*062c5bc4SJason Schmidlapp * following World Wide Web location:
26*062c5bc4SJason Schmidlapp * http://sources.redhat.com/pthreads-win32/contributors.html
27*062c5bc4SJason Schmidlapp *
28*062c5bc4SJason Schmidlapp * This library is free software; you can redistribute it and/or
29*062c5bc4SJason Schmidlapp * modify it under the terms of the GNU Lesser General Public
30*062c5bc4SJason Schmidlapp * License as published by the Free Software Foundation; either
31*062c5bc4SJason Schmidlapp * version 2 of the License, or (at your option) any later version.
32*062c5bc4SJason Schmidlapp *
33*062c5bc4SJason Schmidlapp * This library is distributed in the hope that it will be useful,
34*062c5bc4SJason Schmidlapp * but WITHOUT ANY WARRANTY; without even the implied warranty of
35*062c5bc4SJason Schmidlapp * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36*062c5bc4SJason Schmidlapp * Lesser General Public License for more details.
37*062c5bc4SJason Schmidlapp *
38*062c5bc4SJason Schmidlapp * You should have received a copy of the GNU Lesser General Public
39*062c5bc4SJason Schmidlapp * License along with this library in the file COPYING.LIB;
40*062c5bc4SJason Schmidlapp * if not, write to the Free Software Foundation, Inc.,
41*062c5bc4SJason Schmidlapp * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
42*062c5bc4SJason Schmidlapp */
43*062c5bc4SJason Schmidlapp
44*062c5bc4SJason Schmidlapp #include "pthread.h"
45*062c5bc4SJason Schmidlapp #include "implement.h"
46*062c5bc4SJason Schmidlapp
47*062c5bc4SJason Schmidlapp void
pthread_exit(void * value_ptr)48*062c5bc4SJason Schmidlapp pthread_exit (void *value_ptr)
49*062c5bc4SJason Schmidlapp /*
50*062c5bc4SJason Schmidlapp * ------------------------------------------------------
51*062c5bc4SJason Schmidlapp * DOCPUBLIC
52*062c5bc4SJason Schmidlapp * This function terminates the calling thread, returning
53*062c5bc4SJason Schmidlapp * the value 'value_ptr' to any joining thread.
54*062c5bc4SJason Schmidlapp *
55*062c5bc4SJason Schmidlapp * PARAMETERS
56*062c5bc4SJason Schmidlapp * value_ptr
57*062c5bc4SJason Schmidlapp * a generic data value (i.e. not the address of a value)
58*062c5bc4SJason Schmidlapp *
59*062c5bc4SJason Schmidlapp *
60*062c5bc4SJason Schmidlapp * DESCRIPTION
61*062c5bc4SJason Schmidlapp * This function terminates the calling thread, returning
62*062c5bc4SJason Schmidlapp * the value 'value_ptr' to any joining thread.
63*062c5bc4SJason Schmidlapp * NOTE: thread should be joinable.
64*062c5bc4SJason Schmidlapp *
65*062c5bc4SJason Schmidlapp * RESULTS
66*062c5bc4SJason Schmidlapp * N/A
67*062c5bc4SJason Schmidlapp *
68*062c5bc4SJason Schmidlapp * ------------------------------------------------------
69*062c5bc4SJason Schmidlapp */
70*062c5bc4SJason Schmidlapp {
71*062c5bc4SJason Schmidlapp pte_thread_t * sp;
72*062c5bc4SJason Schmidlapp
73*062c5bc4SJason Schmidlapp /*
74*062c5bc4SJason Schmidlapp * Don't use pthread_self() to avoid creating an implicit POSIX thread handle
75*062c5bc4SJason Schmidlapp * unnecessarily.
76*062c5bc4SJason Schmidlapp */
77*062c5bc4SJason Schmidlapp sp = (pte_thread_t *) pthread_getspecific (pte_selfThreadKey);
78*062c5bc4SJason Schmidlapp
79*062c5bc4SJason Schmidlapp if (NULL == sp)
80*062c5bc4SJason Schmidlapp {
81*062c5bc4SJason Schmidlapp /*
82*062c5bc4SJason Schmidlapp * A POSIX thread handle was never created. I.e. this is a
83*062c5bc4SJason Schmidlapp * Win32 thread that has never called a pthreads-win32 routine that
84*062c5bc4SJason Schmidlapp * required a POSIX handle.
85*062c5bc4SJason Schmidlapp *
86*062c5bc4SJason Schmidlapp * Implicit POSIX handles are cleaned up in pte_throw() now.
87*062c5bc4SJason Schmidlapp */
88*062c5bc4SJason Schmidlapp
89*062c5bc4SJason Schmidlapp /* Terminate thread */
90*062c5bc4SJason Schmidlapp pte_osThreadExit();
91*062c5bc4SJason Schmidlapp
92*062c5bc4SJason Schmidlapp /* Never reached */
93*062c5bc4SJason Schmidlapp }
94*062c5bc4SJason Schmidlapp
95*062c5bc4SJason Schmidlapp sp->exitStatus = value_ptr;
96*062c5bc4SJason Schmidlapp
97*062c5bc4SJason Schmidlapp pte_throw (PTE_EPS_EXIT);
98*062c5bc4SJason Schmidlapp
99*062c5bc4SJason Schmidlapp /* Never reached. */
100*062c5bc4SJason Schmidlapp
101*062c5bc4SJason Schmidlapp }
102