public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Samuel Thibault <sthibaul@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] htl: Let pthread_self and cancellability called early Date: Mon, 1 Aug 2022 22:00:23 +0000 (GMT) [thread overview] Message-ID: <20220801220023.288E9385802B@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=70ff58ced45edf0e3483eddbb61203037bdfdaaa commit 70ff58ced45edf0e3483eddbb61203037bdfdaaa Author: Samuel Thibault <samuel.thibault@ens-lyon.org> Date: Thu Jul 28 22:01:49 2022 +0200 htl: Let pthread_self and cancellability called early When applications redirect some functions they might get called before libpthread is fully initialized. They may still expected pthread_self and cancellable functions to work, so cope with such calls in that situation. Diff: --- htl/cancellation.c | 8 ++++++++ htl/pt-self.c | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/htl/cancellation.c b/htl/cancellation.c index a5d5d2ac04..7d38944718 100644 --- a/htl/cancellation.c +++ b/htl/cancellation.c @@ -25,6 +25,10 @@ int __pthread_enable_asynccancel (void) struct __pthread *p = _pthread_self (); int oldtype; + if (___pthread_self == NULL) + /* We are not initialized yet, we can't be cancelled anyway. */ + return PTHREAD_CANCEL_DEFERRED; + __pthread_mutex_lock (&p->cancel_lock); oldtype = p->cancel_type; p->cancel_type = PTHREAD_CANCEL_ASYNCHRONOUS; @@ -39,6 +43,10 @@ void __pthread_disable_asynccancel (int oldtype) { struct __pthread *p = _pthread_self (); + if (___pthread_self == NULL) + /* We are not initialized yet, we can't be cancelled anyway. */ + return; + __pthread_mutex_lock (&p->cancel_lock); p->cancel_type = oldtype; __pthread_mutex_unlock (&p->cancel_lock); diff --git a/htl/pt-self.c b/htl/pt-self.c index 6fd3c98b82..e05ec69bf5 100644 --- a/htl/pt-self.c +++ b/htl/pt-self.c @@ -24,7 +24,13 @@ pthread_t __pthread_self (void) { - struct __pthread *self = _pthread_self (); + struct __pthread *self; + + if (___pthread_self == NULL) + /* We are not initialized yet, we are the first thread. */ + return 1; + + self = _pthread_self (); assert (self != NULL); return self->thread;
reply other threads:[~2022-08-01 22:00 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220801220023.288E9385802B@sourceware.org \ --to=sthibaul@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).