mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:24:13 +08:00
mdbx-windows: rework mdbx_memalign_alloc()/mdbx_memalign_free() to avoid dependency from CRT.
11 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43 Change-Id: Id1a76f88588251cab9a93aa9753021b30159b09a
This commit is contained in:
parent
f49741b4f8
commit
b47badb3ee
@ -262,8 +262,9 @@ int mdbx_asprintf(char **strp, const char *fmt, ...) {
|
||||
|
||||
#ifndef mdbx_memalign_alloc
|
||||
int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result) {
|
||||
#if _MSC_VER
|
||||
*result = _aligned_malloc(bytes, alignment);
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
(void)alignment;
|
||||
*result = VirtualAlloc(NULL, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
return *result ? MDBX_SUCCESS : MDBX_ENOMEM /* ERROR_OUTOFMEMORY */;
|
||||
#elif __GLIBC_PREREQ(2, 16) || __STDC_VERSION__ >= 201112L
|
||||
*result = memalign(alignment, bytes);
|
||||
@ -279,8 +280,8 @@ int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result) {
|
||||
|
||||
#ifndef mdbx_memalign_free
|
||||
void mdbx_memalign_free(void *ptr) {
|
||||
#if _MSC_VER
|
||||
_aligned_free(ptr);
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
VirtualFree(ptr, 0, MEM_RELEASE);
|
||||
#else
|
||||
mdbx_free(ptr);
|
||||
#endif
|
||||
|
@ -439,8 +439,12 @@ static __inline int mdbx_get_errno(void) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifndef mdbx_memalign_alloc
|
||||
int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result);
|
||||
#endif
|
||||
#ifndef mdbx_memalign_free
|
||||
void mdbx_memalign_free(void *ptr);
|
||||
#endif
|
||||
|
||||
int mdbx_condmutex_init(mdbx_condmutex_t *condmutex);
|
||||
int mdbx_condmutex_lock(mdbx_condmutex_t *condmutex);
|
||||
|
Loading…
x
Reference in New Issue
Block a user