summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>2020-01-06 00:01:10 +0900
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>2020-01-06 00:01:19 +0900
commitfd745bf3cacdd51b58619ae48bfeb0358ddda28e (patch)
tree862b90d3e1240c219405f18f058c9e8f19ab9563 /lib
parentfa6e7f4fb827adb124dbb97a7f72d64e76b2fe6a (diff)
downloadfio-fd745bf3cacdd51b58619ae48bfeb0358ddda28e.tar.gz
fio-fd745bf3cacdd51b58619ae48bfeb0358ddda28e.tar.bz2
lib/memalign: remove smalloc()/sfree() dependency
fio_memalign()/fio_memfree() implementation shouldn't depend on smalloc()/sfree() which has dependency on fio code itself. e.g. This forces unittest code to prepare stab functions for smalloc()/sfree(). This smalloc()/sfree() dependency was added by 3114b675fd ("fio: enable cross-thread overlap checking with processes"). Rename fio_memalign()/fio_memfree() to __fio_memalign()/__fio_memfree() and take a function pointer instead of a boolean flag. Add fio_memalign()/fio_memfree() as an inlined wrapper for __fio_memalign()/__fio_memfree() without API change. The only real change here is lib/memalign functions got renamed. Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/memalign.c15
-rw-r--r--lib/memalign.h7
2 files changed, 9 insertions, 13 deletions
diff --git a/lib/memalign.c b/lib/memalign.c
index 537bb9fb..214a66fa 100644
--- a/lib/memalign.c
+++ b/lib/memalign.c
@@ -11,18 +11,14 @@ struct align_footer {
unsigned int offset;
};
-void *fio_memalign(size_t alignment, size_t size, bool shared)
+void *__fio_memalign(size_t alignment, size_t size, malloc_fn fn)
{
struct align_footer *f;
void *ptr, *ret = NULL;
assert(!(alignment & (alignment - 1)));
- if (shared)
- ptr = smalloc(size + alignment + sizeof(*f) - 1);
- else
- ptr = malloc(size + alignment + sizeof(*f) - 1);
-
+ ptr = fn(size + alignment + sizeof(*f) - 1);
if (ptr) {
ret = PTR_ALIGN(ptr, alignment - 1);
f = ret + size;
@@ -32,12 +28,9 @@ void *fio_memalign(size_t alignment, size_t size, bool shared)
return ret;
}
-void fio_memfree(void *ptr, size_t size, bool shared)
+void __fio_memfree(void *ptr, size_t size, free_fn fn)
{
struct align_footer *f = ptr + size;
- if (shared)
- sfree(ptr - f->offset);
- else
- free(ptr - f->offset);
+ fn(ptr - f->offset);
}
diff --git a/lib/memalign.h b/lib/memalign.h
index d7030870..815e3aa2 100644
--- a/lib/memalign.h
+++ b/lib/memalign.h
@@ -4,7 +4,10 @@
#include <inttypes.h>
#include <stdbool.h>
-extern void *fio_memalign(size_t alignment, size_t size, bool shared);
-extern void fio_memfree(void *ptr, size_t size, bool shared);
+typedef void* (*malloc_fn)(size_t);
+typedef void (*free_fn)(void*);
+
+extern void *__fio_memalign(size_t alignment, size_t size, malloc_fn fn);
+extern void __fio_memfree(void *ptr, size_t size, free_fn fn);
#endif