summaryrefslogtreecommitdiff
path: root/lib/memalign.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/memalign.c')
-rw-r--r--lib/memalign.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/memalign.c b/lib/memalign.c
index e774c19c..537bb9fb 100644
--- a/lib/memalign.c
+++ b/lib/memalign.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include "memalign.h"
+#include "smalloc.h"
#define PTR_ALIGN(ptr, mask) \
(char *)((uintptr_t)((ptr) + (mask)) & ~(mask))
@@ -10,14 +11,18 @@ struct align_footer {
unsigned int offset;
};
-void *fio_memalign(size_t alignment, size_t size)
+void *fio_memalign(size_t alignment, size_t size, bool shared)
{
struct align_footer *f;
void *ptr, *ret = NULL;
assert(!(alignment & (alignment - 1)));
- ptr = malloc(size + alignment + sizeof(*f) - 1);
+ if (shared)
+ ptr = smalloc(size + alignment + sizeof(*f) - 1);
+ else
+ ptr = malloc(size + alignment + sizeof(*f) - 1);
+
if (ptr) {
ret = PTR_ALIGN(ptr, alignment - 1);
f = ret + size;
@@ -27,9 +32,12 @@ void *fio_memalign(size_t alignment, size_t size)
return ret;
}
-void fio_memfree(void *ptr, size_t size)
+void fio_memfree(void *ptr, size_t size, bool shared)
{
struct align_footer *f = ptr + size;
- free(ptr - f->offset);
+ if (shared)
+ sfree(ptr - f->offset);
+ else
+ free(ptr - f->offset);
}