1 /* Start thread. Mach version.
2 Copyright (C) 2000-2024 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 <https://www.gnu.org/licenses/>. */
25 #include <pt-internal.h>
27 /* Prepare a wakeup message. */
29 create_wakeupmsg (struct __pthread
*thread
)
33 /* Build wakeup message. */
34 thread
->wakeupmsg
.msgh_bits
= MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND
, 0);
35 thread
->wakeupmsg
.msgh_size
= 0;
37 err
= __mach_port_allocate (__mach_task_self (), MACH_PORT_RIGHT_RECEIVE
,
38 &thread
->wakeupmsg
.msgh_remote_port
);
42 thread
->wakeupmsg
.msgh_local_port
= MACH_PORT_NULL
;
43 thread
->wakeupmsg
.msgh_seqno
= 0;
44 thread
->wakeupmsg
.msgh_id
= 0;
46 err
= __mach_port_insert_right (__mach_task_self (),
47 thread
->wakeupmsg
.msgh_remote_port
,
48 thread
->wakeupmsg
.msgh_remote_port
,
49 MACH_MSG_TYPE_MAKE_SEND
);
52 __mach_port_destroy (__mach_task_self (),
53 thread
->wakeupmsg
.msgh_remote_port
);
57 /* No need to queue more than one wakeup message on this port. */
58 __mach_port_set_qlimit (__mach_task_self (),
59 thread
->wakeupmsg
.msgh_remote_port
, 1);
64 /* Allocate any resources for THREAD. The new kernel thread should not
65 be eligible to be scheduled. */
67 __pthread_thread_alloc (struct __pthread
*thread
)
72 err
= create_wakeupmsg (thread
);
78 assert (__pthread_total
== 0);
79 thread
->kernel_thread
= __mach_thread_self ();
84 err
= __thread_create (__mach_task_self (), &thread
->kernel_thread
);
87 __mach_port_destroy (__mach_task_self (),
88 thread
->wakeupmsg
.msgh_remote_port
);