summaryrefslogtreecommitdiff
path: root/htl/pt-create.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2025-11-16 14:09:11 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2025-11-17 00:38:37 +0000
commit5b6ee0e0ba7321ca37db12a942493e4ea8eead92 (patch)
tree831dc5b6ba00e85e9ecf5a3df8cf4a7ab36c7fd5 /htl/pt-create.c
parentf63dd924312919667f8c71f7701523dfdc542067 (diff)
htl: move pthread_create to into libc
This is notably needed for the main thread structure to be always initialized so that some pthread functions can work from the main thread without other threads, e.g. pthread_cancel.
Diffstat (limited to 'htl/pt-create.c')
-rw-r--r--htl/pt-create.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/htl/pt-create.c b/htl/pt-create.c
index d3fee29d20..820037e8a9 100644
--- a/htl/pt-create.c
+++ b/htl/pt-create.c
@@ -25,13 +25,14 @@
#include <atomic.h>
#include <hurd/resource.h>
#include <sys/single_threaded.h>
+#include <shlib-compat.h>
+#include <ldsodefs.h>
#include <pt-internal.h>
#include <pthreadP.h>
-#if IS_IN (libpthread)
-# include <ctype.h>
-#endif
+#include <ctype.h>
+
#ifdef HAVE_USELOCALE
# include <locale.h>
#endif
@@ -45,10 +46,9 @@ entry_point (struct __pthread *self, void *(*start_routine) (void *), void *arg)
___pthread_self = self;
__resp = &self->res_state;
-#if IS_IN (libpthread)
/* Initialize pointers to locale data. */
__ctype_init ();
-#endif
+
#ifdef HAVE_USELOCALE
/* A fresh thread needs to be bound to the global locale. */
uselocale (LC_GLOBAL_LOCALE);
@@ -79,6 +79,24 @@ int
__pthread_create (pthread_t * thread, const pthread_attr_t * attr,
void *(*start_routine) (void *), void *arg)
{
+ /* Avoid a data race in the multi-threaded case. */
+ if (__libc_single_threaded)
+ __libc_single_threaded = 0;
+
+ return __libc_pthread_create (thread, attr, start_routine, arg);
+}
+versioned_symbol (libc, __pthread_create, pthread_create, GLIBC_2_43);
+#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_12, GLIBC_2_43)
+compat_symbol (libpthread, __pthread_create, pthread_create, GLIBC_2_12);
+#endif
+hidden_def (__pthread_create)
+
+/* Version of pthread_create which does not make __libc_single_threaded zero.
+ This is notably useful for the signal thread. */
+int
+__libc_pthread_create (pthread_t * thread, const pthread_attr_t * attr,
+ void *(*start_routine) (void *), void *arg)
+{
int err;
struct __pthread *pthread;
@@ -90,8 +108,6 @@ __pthread_create (pthread_t * thread, const pthread_attr_t * attr,
return err;
}
-weak_alias (__pthread_create, pthread_create)
-hidden_def (__pthread_create)
/* Internal version of pthread_create. See comment in
pt-internal.h. */
@@ -106,10 +122,6 @@ __pthread_create_internal (struct __pthread **thread,
sigset_t sigset;
size_t stacksize;
- /* Avoid a data race in the multi-threaded case. */
- if (__libc_single_threaded)
- __libc_single_threaded = 0;
-
/* Allocate a new thread structure. */
err = __pthread_alloc (&pthread);
if (err)