Don't mix pattern rules with normal rules
[glibc.git] / elf / dl-scope.c
blob229177ed340873c7e6b6b449043b9eb18afe4cbc
1 /* Memory handling for the scope data structures.
2 Copyright (C) 2009 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <stdlib.h>
21 #include <ldsodefs.h>
22 #include <sysdep-cancel.h>
25 int
26 _dl_scope_free (void *old)
28 struct dl_scope_free_list *fsl;
29 #define DL_SCOPE_FREE_LIST_SIZE (sizeof (fsl->list) / sizeof (fsl->list[0]))
31 if (RTLD_SINGLE_THREAD_P)
32 free (old);
33 else if ((fsl = GL(dl_scope_free_list)) == NULL)
35 GL(dl_scope_free_list) = fsl = malloc (sizeof (*fsl));
36 if (fsl == NULL)
38 THREAD_GSCOPE_WAIT ();
39 free (old);
40 return 1;
42 else
44 fsl->list[0] = old;
45 fsl->count = 1;
48 else if (fsl->count < DL_SCOPE_FREE_LIST_SIZE)
49 fsl->list[fsl->count++] = old;
50 else
52 THREAD_GSCOPE_WAIT ();
53 while (fsl->count > 0)
54 free (fsl->list[--fsl->count]);
55 return 1;
57 return 0;