NaCl: Set tid field to a unique value.
[glibc.git] / sysdeps / nacl / createthread.c
blob9d9284a7b50638f267b2aca6e31696322554d463
1 /* Low-level thread creation for NPTL. NaCl version.
2 Copyright (C) 2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <nacl-interfaces.h>
20 #include <pthread-pids.h>
22 /* See the comments in pthread_create.c for the requirements for these
23 two macros and the create_thread function. */
25 #define START_THREAD_DEFN \
26 static void __attribute__ ((noreturn)) start_thread (void)
27 #define START_THREAD_SELF THREAD_SELF
29 /* pthread_create.c defines this using START_THREAD_DEFN
30 We need a forward declaration here so we can take its address. */
31 static void start_thread (void) __attribute__ ((noreturn));
33 static int
34 create_thread (struct pthread *pd, const struct pthread_attr *attr,
35 bool stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
37 pd->tid = __nacl_get_tid (pd);
39 pd->stopped_start = stopped_start;
40 if (__glibc_unlikely (stopped_start))
41 /* We make sure the thread does not run far by forcing it to get a
42 lock. We lock it here too so that the new thread cannot continue
43 until we tell it to. */
44 lll_lock (pd->lock, LLL_PRIVATE);
46 TLS_DEFINE_INIT_TP (tp, pd);
48 return __nacl_irt_thread.thread_create (&start_thread, stackaddr, tp);