summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/imports.c
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2006-08-16 17:06:08 +0000
committerIan Romanick <[email protected]>2006-08-16 17:06:08 +0000
commita7d02567451f69445ef31181a41b16e86487093d (patch)
tree6e42bb8e124f17e6f5e8b0b5dcc76b0832d6e997 /src/mesa/main/imports.c
parentab6cf9dd622c4659aa5f47cb1b5f86b8e38d5a85 (diff)
When available, which is most of the time, use posix_memalign to implement
_mesa_align_malloc and friends.
Diffstat (limited to 'src/mesa/main/imports.c')
-rw-r--r--src/mesa/main/imports.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index b506f856a69..08f44a8f88a 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -131,6 +131,12 @@ _mesa_free(void *ptr)
void *
_mesa_align_malloc(size_t bytes, unsigned long alignment)
{
+#if defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE))
+ void *mem;
+
+ (void) posix_memalign(& mem, alignment, bytes);
+ return mem;
+#else
uintptr_t ptr, buf;
ASSERT( alignment > 0 );
@@ -151,6 +157,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
#endif
return (void *) buf;
+#endif /* defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE)) */
}
/**
@@ -160,6 +167,16 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
void *
_mesa_align_calloc(size_t bytes, unsigned long alignment)
{
+#if defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE))
+ void *mem;
+
+ mem = _mesa_align_malloc(bytes, alignment);
+ if (mem != NULL) {
+ (void) memset(mem, 0, bytes);
+ }
+
+ return mem;
+#else
uintptr_t ptr, buf;
ASSERT( alignment > 0 );
@@ -180,6 +197,7 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
#endif
return (void *)buf;
+#endif /* defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE)) */
}
/**
@@ -192,13 +210,13 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
void
_mesa_align_free(void *ptr)
{
-#if 0
- _mesa_free( (void *)(*(unsigned long *)((unsigned long)ptr - sizeof(void *))) );
+#if defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE))
+ free(ptr);
#else
void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
void *realAddr = *cubbyHole;
_mesa_free(realAddr);
-#endif
+#endif /* defined(HAVE_POSIX_MEMALIGN) && !(defined(XFree86LOADER) && defined(IN_MODULE)) */
}
/**