@@ -86,6 +86,15 @@ enum memmodel
/* alloc.c */
+#if defined(HAVE_ALIGNED_ALLOC) \
+ || defined(HAVE__ALIGNED_MALLOC) \
+ || defined(HAVE_POSIX_MEMALIGN) \
+ || defined(HAVE_MEMALIGN)
+/* Defined if gomp_aligned_alloc doesn't use fallback version
+ and free can be used instead of gomp_aligned_free. */
+#define GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC 1
+#endif
+
extern void *gomp_malloc (size_t) __attribute__((malloc));
extern void *gomp_malloc_cleared (size_t) __attribute__((malloc));
extern void *gomp_realloc (void *, size_t);
@@ -87,7 +87,6 @@ gomp_aligned_alloc (size_t al, size_t si
((void **) ap)[-1] = p;
ret = ap;
}
-#define NEED_SPECIAL_GOMP_ALIGNED_FREE
}
#endif
if (ret == NULL)
@@ -98,10 +97,10 @@ gomp_aligned_alloc (size_t al, size_t si
void
gomp_aligned_free (void *ptr)
{
-#ifdef NEED_SPECIAL_GOMP_ALIGNED_FREE
+#ifdef GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC
+ free (ptr);
+#else
if (ptr)
free (((void **) ptr)[-1]);
-#else
- free (ptr);
#endif
}
@@ -76,7 +76,15 @@ alloc_work_share (struct gomp_team *team
#endif
team->work_share_chunk *= 2;
+ /* Allocating gomp_work_share structures aligned is just an
+ optimization, don't do it when using the fallback method. */
+#ifdef GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC
+ ws = gomp_aligned_alloc (__alignof (struct gomp_work_share),
+ team->work_share_chunk
+ * sizeof (struct gomp_work_share));
+#else
ws = gomp_malloc (team->work_share_chunk * sizeof (struct gomp_work_share));
+#endif
ws->next_alloc = team->work_shares[0].next_alloc;
team->work_shares[0].next_alloc = ws;
team->work_share_list_alloc = &ws[1];