/[pcsx2_0.9.7]/trunk/3rdparty/w32pthreads/pthread_self.c
ViewVC logotype

Contents of /trunk/3rdparty/w32pthreads/pthread_self.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 3946 byte(s)
committing r3113 initial commit again...
1 /*
2 * pthread_self.c
3 *
4 * Description:
5 * This translation unit implements miscellaneous thread functions.
6 *
7 * --------------------------------------------------------------------------
8 *
9 * Pthreads-win32 - POSIX Threads Library for Win32
10 * Copyright(C) 1998 John E. Bossom
11 * Copyright(C) 1999,2005 Pthreads-win32 contributors
12 *
13 * Contact Email: rpj@callisto.canberra.edu.au
14 *
15 * The current list of contributors is contained
16 * in the file CONTRIBUTORS included with the source
17 * code distribution. The list can also be seen at the
18 * following World Wide Web location:
19 * http://sources.redhat.com/pthreads-win32/contributors.html
20 *
21 * This library is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public
23 * License as published by the Free Software Foundation; either
24 * version 2 of the License, or (at your option) any later version.
25 *
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library in the file COPYING.LIB;
33 * if not, write to the Free Software Foundation, Inc.,
34 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
35 */
36
37 #include "ptw32pch.h"
38
39 pthread_t
40 pthread_self (void)
41 /*
42 * ------------------------------------------------------
43 * DOCPUBLIC
44 * This function returns a reference to the current running
45 * thread.
46 *
47 * PARAMETERS
48 * N/A
49 *
50 *
51 * DESCRIPTION
52 * This function returns a reference to the current running
53 * thread.
54 *
55 * RESULTS
56 * pthread_t reference to the current thread
57 *
58 * ------------------------------------------------------
59 */
60 {
61 pthread_t self;
62 pthread_t nil = {NULL, 0};
63 ptw32_thread_t * sp;
64
65 #ifdef _UWIN
66 if (!ptw32_selfThreadKey)
67 return nil;
68 #endif
69
70 sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
71
72 if (sp != NULL)
73 {
74 self = sp->ptHandle;
75 }
76 else
77 {
78 /*
79 * Need to create an implicit 'self' for the currently
80 * executing thread.
81 */
82 self = ptw32_new ();
83 sp = (ptw32_thread_t *) self.p;
84
85 if (sp != NULL)
86 {
87 /*
88 * This is a non-POSIX thread which has chosen to call
89 * a POSIX threads function for some reason. We assume that
90 * it isn't joinable, but we do assume that it's
91 * (deferred) cancelable.
92 */
93 sp->implicit = 1;
94 sp->detachState = PTHREAD_CREATE_DETACHED;
95 sp->thread = GetCurrentThreadId ();
96
97 #ifdef NEED_DUPLICATEHANDLE
98 /*
99 * DuplicateHandle does not exist on WinCE.
100 *
101 * NOTE:
102 * GetCurrentThread only returns a pseudo-handle
103 * which is only valid in the current thread context.
104 * Therefore, you should not pass the handle to
105 * other threads for whatever purpose.
106 */
107 sp->threadH = GetCurrentThread ();
108 #else
109 if (!DuplicateHandle (GetCurrentProcess (),
110 GetCurrentThread (),
111 GetCurrentProcess (),
112 &sp->threadH,
113 0, FALSE, DUPLICATE_SAME_ACCESS))
114 {
115 /*
116 * Should not do this, but we have no alternative if
117 * we can't get a Win32 thread handle.
118 * Thread structs are never freed.
119 */
120 ptw32_threadReusePush (self);
121 return nil;
122 }
123 #endif
124
125 /*
126 * No need to explicitly serialise access to sched_priority
127 * because the new handle is not yet public.
128 */
129 sp->sched_priority = GetThreadPriority (sp->threadH);
130
131 pthread_setspecific (ptw32_selfThreadKey, (void *) sp);
132 }
133 }
134
135 return (self);
136
137 } /* pthread_self */

  ViewVC Help
Powered by ViewVC 1.1.22