Mercurial > hg > CbC > CbC_gcc
comparison libgomp/alloc.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Copyright (C) 2005-2018 Free Software Foundation, Inc. | 1 /* Copyright (C) 2005-2020 Free Software Foundation, Inc. |
2 Contributed by Richard Henderson <rth@redhat.com>. | 2 Contributed by Richard Henderson <rth@redhat.com>. |
3 | 3 |
4 This file is part of the GNU Offloading and Multi Processing Library | 4 This file is part of the GNU Offloading and Multi Processing Library |
5 (libgomp). | 5 (libgomp). |
6 | 6 |
25 | 25 |
26 /* This file contains wrappers for the system allocation routines. Most | 26 /* This file contains wrappers for the system allocation routines. Most |
27 places in the OpenMP API do not make any provision for failure, so in | 27 places in the OpenMP API do not make any provision for failure, so in |
28 general we cannot allow memory allocation to fail. */ | 28 general we cannot allow memory allocation to fail. */ |
29 | 29 |
30 #define _GNU_SOURCE | |
30 #include "libgomp.h" | 31 #include "libgomp.h" |
31 #include <stdlib.h> | 32 #include <stdlib.h> |
32 | 33 |
33 | 34 |
34 void * | 35 void * |
55 void *ret = realloc (old, size); | 56 void *ret = realloc (old, size); |
56 if (ret == NULL) | 57 if (ret == NULL) |
57 gomp_fatal ("Out of memory allocating %lu bytes", (unsigned long) size); | 58 gomp_fatal ("Out of memory allocating %lu bytes", (unsigned long) size); |
58 return ret; | 59 return ret; |
59 } | 60 } |
61 | |
62 void * | |
63 gomp_aligned_alloc (size_t al, size_t size) | |
64 { | |
65 void *ret; | |
66 if (al < sizeof (void *)) | |
67 al = sizeof (void *); | |
68 #ifdef HAVE_ALIGNED_ALLOC | |
69 ret = aligned_alloc (al, size); | |
70 #elif defined(HAVE__ALIGNED_MALLOC) | |
71 ret = _aligned_malloc (size, al); | |
72 #elif defined(HAVE_POSIX_MEMALIGN) | |
73 if (posix_memalign (&ret, al, size) != 0) | |
74 ret = NULL; | |
75 #elif defined(HAVE_MEMALIGN) | |
76 { | |
77 extern void *memalign (size_t, size_t); | |
78 ret = memalign (al, size); | |
79 } | |
80 #else | |
81 ret = NULL; | |
82 if ((al & (al - 1)) == 0 && size) | |
83 { | |
84 void *p = malloc (size + al); | |
85 if (p) | |
86 { | |
87 void *ap = (void *) (((uintptr_t) p + al) & -al); | |
88 ((void **) ap)[-1] = p; | |
89 ret = ap; | |
90 } | |
91 } | |
92 #endif | |
93 if (ret == NULL) | |
94 gomp_fatal ("Out of memory allocating %lu bytes", (unsigned long) size); | |
95 return ret; | |
96 } | |
97 | |
98 void | |
99 gomp_aligned_free (void *ptr) | |
100 { | |
101 #ifdef GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC | |
102 free (ptr); | |
103 #else | |
104 if (ptr) | |
105 free (((void **) ptr)[-1]); | |
106 #endif | |
107 } |