]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/gai_misc.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / mach / hurd / gai_misc.h
1 /* Copyright (C) 2006-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #include <assert.h>
19 #include <signal.h>
20 #include <pthread.h>
21
22 #define gai_start_notify_thread __gai_start_notify_thread
23 #define gai_create_helper_thread __gai_create_helper_thread
24
25 extern inline void
26 __gai_start_notify_thread (void)
27 {
28 sigset_t ss;
29 sigemptyset (&ss);
30 int sigerr __attribute__ ((unused));
31 sigerr = pthread_sigmask (SIG_SETMASK, &ss, NULL);
32 assert_perror (sigerr);
33 }
34
35 extern inline int
36 __gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
37 void *arg)
38 {
39 pthread_attr_t attr;
40
41 /* Make sure the thread is created detached. */
42 pthread_attr_init (&attr);
43 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
44
45 /* The helper thread needs only very little resources. */
46 (void) pthread_attr_setstacksize (&attr, 0x10000);
47
48 /* Block all signals in the helper thread. To do this thoroughly we
49 temporarily have to block all signals here. */
50 sigset_t ss;
51 sigset_t oss;
52 sigfillset (&ss);
53 int sigerr __attribute__ ((unused));
54 sigerr = pthread_sigmask (SIG_SETMASK, &ss, &oss);
55 assert_perror (sigerr);
56
57 int ret = pthread_create (threadp, &attr, tf, arg);
58
59 /* Restore the signal mask. */
60 sigerr = pthread_sigmask (SIG_SETMASK, &oss, NULL);
61 assert_perror (sigerr);
62
63 (void) pthread_attr_destroy (&attr);
64 return ret;
65 }
66
67 #include_next <gai_misc.h>