1/* A thread attribute with a small stack.
2 Copyright (C) 2019-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#include <support/xthread.h>
20#include <allocate_once.h>
21
22static void *
23allocate (void *closure)
24{
25 pthread_attr_t *result = malloc (size: sizeof (*result));
26 xpthread_attr_init (attr: result);
27 support_set_small_thread_stack_size (attr: result);
28 return result;
29}
30
31static void
32deallocate (void *ptr, void *closure)
33{
34 xpthread_attr_destroy (attr: ptr);
35 free (ptr: ptr);
36}
37
38static void *small_stack_attr;
39
40pthread_attr_t *
41support_small_stack_thread_attribute (void)
42{
43 return allocate_once (place: &small_stack_attr, allocate: allocate, deallocate: deallocate, NULL);
44}
45
46static void __attribute__ ((destructor))
47fini (void)
48{
49 if (small_stack_attr != NULL)
50 {
51 deallocate (ptr: small_stack_attr, NULL);
52 small_stack_attr = NULL;
53 }
54}
55

source code of glibc/support/support_small_stack_thread_attribute.c