aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-24 12:11:13 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-24 14:05:18 +0100
commit930eb71b8e2e1cbd4a6e9fd50a5253e44b79c2b1 (patch)
tree67e50eb12bd56cdd14938fad88c59e17bb0e2594 /lib
parent14d0d4d55ed579c471ec24c03cb3808d4d721a79 (diff)
Port the pool allocator to Windows
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/util/mempool.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/util/mempool.c b/lib/util/mempool.c
index 57aab4d..3e0b0c9 100644
--- a/lib/util/mempool.c
+++ b/lib/util/mempool.c
@@ -11,7 +11,12 @@
#include <string.h>
#include <assert.h>
+#if defined(_WIN32) || defined(__WINDOWS__)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#else
#include <sys/mman.h>
+#endif
#define DEF_POOL_SIZE (65536)
#define MEM_ALIGN (8)
@@ -60,11 +65,19 @@ static pool_t *create_pool(const mem_pool_t *mem)
unsigned char *ptr;
pool_t *pool;
+#if defined(_WIN32) || defined(__WINDOWS__)
+ ptr = VirtualAlloc(NULL, mem->pool_size, MEM_RESERVE | MEM_COMMIT,
+ PAGE_READWRITE);
+
+ if (ptr == NULL)
+ return NULL;
+#else
ptr = mmap(NULL, mem->pool_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (ptr == MAP_FAILED)
return NULL;
+#endif
pool = (pool_t *)ptr;
@@ -124,7 +137,11 @@ void mem_pool_destroy(mem_pool_t *mem)
pool_t *pool = mem->pool_list;
mem->pool_list = pool->next;
+#if defined(_WIN32) || defined(__WINDOWS__)
+ VirtualFree(pool, mem->pool_size, MEM_RELEASE);
+#else
munmap(pool, mem->pool_size);
+#endif
}
free(mem);