mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 02:24:14 +08:00
mdbx: use MAP_NOSYNC & MAP_HASSEMAPHORE if defined (compatibility).
This commit is contained in:
parent
885d5b2121
commit
fc48751f8f
@ -8047,7 +8047,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = mdbx_mmap(env->me_flags, &env->me_dxb_mmap, env->me_dbgeo.now,
|
err = mdbx_mmap(env->me_flags, &env->me_dxb_mmap, env->me_dbgeo.now,
|
||||||
env->me_dbgeo.upper, lck_rc);
|
env->me_dbgeo.upper, lck_rc ? MMAP_OPTION_TRUNCATE : 0);
|
||||||
if (unlikely(err != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@ -8379,7 +8379,8 @@ static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname,
|
|||||||
env->me_maxreaders = (unsigned)maxreaders;
|
env->me_maxreaders = (unsigned)maxreaders;
|
||||||
|
|
||||||
err = mdbx_mmap(MDBX_WRITEMAP, &env->me_lck_mmap, (size_t)size, (size_t)size,
|
err = mdbx_mmap(MDBX_WRITEMAP, &env->me_lck_mmap, (size_t)size, (size_t)size,
|
||||||
lck_seize_rc);
|
lck_seize_rc ? MMAP_OPTION_TRUNCATE | MMAP_OPTION_SEMAPHORE
|
||||||
|
: MMAP_OPTION_SEMAPHORE);
|
||||||
if (unlikely(err != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
goto bailout;
|
goto bailout;
|
||||||
|
|
||||||
|
@ -1166,7 +1166,7 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
|
|||||||
|
|
||||||
MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
||||||
const size_t size, const size_t limit,
|
const size_t size, const size_t limit,
|
||||||
const bool truncate) {
|
const unsigned options) {
|
||||||
assert(size <= limit);
|
assert(size <= limit);
|
||||||
map->limit = 0;
|
map->limit = 0;
|
||||||
map->current = 0;
|
map->current = 0;
|
||||||
@ -1180,7 +1180,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
|||||||
if (unlikely(err != MDBX_SUCCESS))
|
if (unlikely(err != MDBX_SUCCESS))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if ((flags & MDBX_RDONLY) == 0 && truncate) {
|
if ((flags & MDBX_RDONLY) == 0 && (options & MMAP_OPTION_TRUNCATE) != 0) {
|
||||||
err = mdbx_ftruncate(map->fd, size);
|
err = mdbx_ftruncate(map->fd, size);
|
||||||
if (err != MDBX_SUCCESS)
|
if (err != MDBX_SUCCESS)
|
||||||
return err;
|
return err;
|
||||||
@ -1243,7 +1243,18 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
|||||||
|
|
||||||
map->address = mmap(
|
map->address = mmap(
|
||||||
NULL, limit, (flags & MDBX_WRITEMAP) ? PROT_READ | PROT_WRITE : PROT_READ,
|
NULL, limit, (flags & MDBX_WRITEMAP) ? PROT_READ | PROT_WRITE : PROT_READ,
|
||||||
MAP_SHARED, map->fd, 0);
|
MAP_SHARED | MAP_FILE
|
||||||
|
#ifdef MAP_NOSYNC
|
||||||
|
| (((options & MMAP_OPTION_SEMAPHORE) != 0 ||
|
||||||
|
F_ISSET(flags, MDBX_UTTERLY_NOSYNC))
|
||||||
|
? MAP_NOSYNC
|
||||||
|
: 0)
|
||||||
|
#endif
|
||||||
|
#ifdef MAP_HASSEMAPHORE
|
||||||
|
| ((options & MMAP_OPTION_SEMAPHORE) ? MAP_HASSEMAPHORE : 0)
|
||||||
|
#endif
|
||||||
|
,
|
||||||
|
map->fd, 0);
|
||||||
|
|
||||||
if (unlikely(map->address == MAP_FAILED)) {
|
if (unlikely(map->address == MAP_FAILED)) {
|
||||||
map->limit = 0;
|
map->limit = 0;
|
||||||
|
@ -649,9 +649,11 @@ typedef struct mdbx_mmap_param {
|
|||||||
#endif
|
#endif
|
||||||
} mdbx_mmap_t;
|
} mdbx_mmap_t;
|
||||||
|
|
||||||
|
#define MMAP_OPTION_TRUNCATE 1
|
||||||
|
#define MMAP_OPTION_SEMAPHORE 2
|
||||||
MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
||||||
const size_t must, const size_t limit,
|
const size_t must, const size_t limit,
|
||||||
const bool truncate);
|
const unsigned options);
|
||||||
MDBX_INTERNAL_FUNC int mdbx_munmap(mdbx_mmap_t *map);
|
MDBX_INTERNAL_FUNC int mdbx_munmap(mdbx_mmap_t *map);
|
||||||
MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t current,
|
MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t current,
|
||||||
size_t wanna);
|
size_t wanna);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user