|
|
@ -62,12 +62,15 @@ |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if defined(__APPLE__) || defined (BSD) |
|
|
|
#if defined(__APPLE__) || defined (BSD) |
|
|
|
#define USE_POSIX_SEM |
|
|
|
# define MDB_USE_POSIX_SEM 1 |
|
|
|
|
|
|
|
# define MDB_FDATASYNC fsync |
|
|
|
|
|
|
|
#elif defined(ANDROID) |
|
|
|
|
|
|
|
# define MDB_FDATASYNC fsync |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
#ifndef _WIN32 |
|
|
|
#include <pthread.h> |
|
|
|
#include <pthread.h> |
|
|
|
#ifdef USE_POSIX_SEM |
|
|
|
#ifdef MDB_USE_POSIX_SEM |
|
|
|
#include <semaphore.h> |
|
|
|
#include <semaphore.h> |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -155,16 +158,12 @@ |
|
|
|
#define close(fd) CloseHandle(fd) |
|
|
|
#define close(fd) CloseHandle(fd) |
|
|
|
#define munmap(ptr,len) UnmapViewOfFile(ptr) |
|
|
|
#define munmap(ptr,len) UnmapViewOfFile(ptr) |
|
|
|
#else |
|
|
|
#else |
|
|
|
#ifdef USE_POSIX_SEM |
|
|
|
#ifdef MDB_USE_POSIX_SEM |
|
|
|
#define LOCK_MUTEX_R(env) sem_wait((env)->me_rmutex) |
|
|
|
#define LOCK_MUTEX_R(env) sem_wait((env)->me_rmutex) |
|
|
|
#define UNLOCK_MUTEX_R(env) sem_post((env)->me_rmutex) |
|
|
|
#define UNLOCK_MUTEX_R(env) sem_post((env)->me_rmutex) |
|
|
|
#define LOCK_MUTEX_W(env) sem_wait((env)->me_wmutex) |
|
|
|
#define LOCK_MUTEX_W(env) sem_wait((env)->me_wmutex) |
|
|
|
#define UNLOCK_MUTEX_W(env) sem_post((env)->me_wmutex) |
|
|
|
#define UNLOCK_MUTEX_W(env) sem_post((env)->me_wmutex) |
|
|
|
#define MDB_FDATASYNC(fd) fsync(fd) |
|
|
|
|
|
|
|
#else |
|
|
|
#else |
|
|
|
#ifdef ANDROID |
|
|
|
|
|
|
|
#define MDB_FDATASYNC(fd) fsync(fd) |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
/** Lock the reader mutex.
|
|
|
|
/** Lock the reader mutex.
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#define LOCK_MUTEX_R(env) pthread_mutex_lock(&(env)->me_txns->mti_mutex) |
|
|
|
#define LOCK_MUTEX_R(env) pthread_mutex_lock(&(env)->me_txns->mti_mutex) |
|
|
@ -180,7 +179,7 @@ |
|
|
|
/** Unlock the writer mutex.
|
|
|
|
/** Unlock the writer mutex.
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#define UNLOCK_MUTEX_W(env) pthread_mutex_unlock(&(env)->me_txns->mti_wmutex) |
|
|
|
#define UNLOCK_MUTEX_W(env) pthread_mutex_unlock(&(env)->me_txns->mti_wmutex) |
|
|
|
#endif /* USE_POSIX_SEM */ |
|
|
|
#endif /* MDB_USE_POSIX_SEM */ |
|
|
|
|
|
|
|
|
|
|
|
/** Get the error code for the last failed system function.
|
|
|
|
/** Get the error code for the last failed system function.
|
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -205,7 +204,7 @@ |
|
|
|
#define GET_PAGESIZE(x) ((x) = sysconf(_SC_PAGE_SIZE)) |
|
|
|
#define GET_PAGESIZE(x) ((x) = sysconf(_SC_PAGE_SIZE)) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(USE_POSIX_SEM) |
|
|
|
#if defined(_WIN32) || defined(MDB_USE_POSIX_SEM) |
|
|
|
#define MNAME_LEN 32 |
|
|
|
#define MNAME_LEN 32 |
|
|
|
#else |
|
|
|
#else |
|
|
|
#define MNAME_LEN (sizeof(pthread_mutex_t)) |
|
|
|
#define MNAME_LEN (sizeof(pthread_mutex_t)) |
|
|
@ -481,7 +480,7 @@ typedef struct MDB_txbody { |
|
|
|
uint32_t mtb_magic; |
|
|
|
uint32_t mtb_magic; |
|
|
|
/** Version number of this lock file. Must be set to #MDB_VERSION. */ |
|
|
|
/** Version number of this lock file. Must be set to #MDB_VERSION. */ |
|
|
|
uint32_t mtb_version; |
|
|
|
uint32_t mtb_version; |
|
|
|
#if defined(_WIN32) || defined(USE_POSIX_SEM) |
|
|
|
#if defined(_WIN32) || defined(MDB_USE_POSIX_SEM) |
|
|
|
char mtb_rmname[MNAME_LEN]; |
|
|
|
char mtb_rmname[MNAME_LEN]; |
|
|
|
#else |
|
|
|
#else |
|
|
|
/** Mutex protecting access to this table.
|
|
|
|
/** Mutex protecting access to this table.
|
|
|
@ -514,7 +513,7 @@ typedef struct MDB_txninfo { |
|
|
|
char pad[(sizeof(MDB_txbody)+CACHELINE-1) & ~(CACHELINE-1)]; |
|
|
|
char pad[(sizeof(MDB_txbody)+CACHELINE-1) & ~(CACHELINE-1)]; |
|
|
|
} mt1; |
|
|
|
} mt1; |
|
|
|
union { |
|
|
|
union { |
|
|
|
#if defined(_WIN32) || defined(USE_POSIX_SEM) |
|
|
|
#if defined(_WIN32) || defined(MDB_USE_POSIX_SEM) |
|
|
|
char mt2_wmname[MNAME_LEN]; |
|
|
|
char mt2_wmname[MNAME_LEN]; |
|
|
|
#define mti_wmname mt2.mt2_wmname |
|
|
|
#define mti_wmname mt2.mt2_wmname |
|
|
|
#else |
|
|
|
#else |
|
|
@ -930,9 +929,8 @@ struct MDB_env { |
|
|
|
#ifdef _WIN32 |
|
|
|
#ifdef _WIN32 |
|
|
|
HANDLE me_rmutex; /* Windows mutexes don't reside in shared mem */ |
|
|
|
HANDLE me_rmutex; /* Windows mutexes don't reside in shared mem */ |
|
|
|
HANDLE me_wmutex; |
|
|
|
HANDLE me_wmutex; |
|
|
|
#endif |
|
|
|
#elif defined(MDB_USE_POSIX_SEM) |
|
|
|
#ifdef USE_POSIX_SEM |
|
|
|
sem_t *me_rmutex; /* Shared mutexes are not supported */ |
|
|
|
sem_t *me_rmutex; /* Apple doesn't support shared mutexes */ |
|
|
|
|
|
|
|
sem_t *me_wmutex; |
|
|
|
sem_t *me_wmutex; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
}; |
|
|
|
}; |
|
|
@ -2792,7 +2790,7 @@ mdb_env_excl_lock(MDB_env *env, int *excl) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(USE_POSIX_SEM) |
|
|
|
#if defined(_WIN32) || defined(MDB_USE_POSIX_SEM) |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* hash_64 - 64 bit Fowler/Noll/Vo-0 FNV-1a hash code |
|
|
|
* hash_64 - 64 bit Fowler/Noll/Vo-0 FNV-1a hash code |
|
|
|
* |
|
|
|
* |
|
|
@ -3002,8 +3000,7 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl) |
|
|
|
rc = ErrCode(); |
|
|
|
rc = ErrCode(); |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
} |
|
|
|
} |
|
|
|
#else /* _WIN32 */ |
|
|
|
#elif defined(MDB_USE_POSIX_SEM) |
|
|
|
#ifdef USE_POSIX_SEM |
|
|
|
|
|
|
|
struct stat stbuf; |
|
|
|
struct stat stbuf; |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
dev_t dev; |
|
|
|
dev_t dev; |
|
|
@ -3040,7 +3037,7 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl) |
|
|
|
rc = ErrCode(); |
|
|
|
rc = ErrCode(); |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
} |
|
|
|
} |
|
|
|
#else /* USE_POSIX_SEM */ |
|
|
|
#else /* MDB_USE_POSIX_SEM */ |
|
|
|
pthread_mutexattr_t mattr; |
|
|
|
pthread_mutexattr_t mattr; |
|
|
|
|
|
|
|
|
|
|
|
pthread_mutexattr_init(&mattr); |
|
|
|
pthread_mutexattr_init(&mattr); |
|
|
@ -3050,8 +3047,7 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl) |
|
|
|
} |
|
|
|
} |
|
|
|
pthread_mutex_init(&env->me_txns->mti_mutex, &mattr); |
|
|
|
pthread_mutex_init(&env->me_txns->mti_mutex, &mattr); |
|
|
|
pthread_mutex_init(&env->me_txns->mti_wmutex, &mattr); |
|
|
|
pthread_mutex_init(&env->me_txns->mti_wmutex, &mattr); |
|
|
|
#endif /* USE_POSIX_SEM */ |
|
|
|
#endif /* _WIN32 || MDB_USE_POSIX_SEM */ |
|
|
|
#endif /* _WIN32 */ |
|
|
|
|
|
|
|
env->me_txns->mti_version = MDB_VERSION; |
|
|
|
env->me_txns->mti_version = MDB_VERSION; |
|
|
|
env->me_txns->mti_magic = MDB_MAGIC; |
|
|
|
env->me_txns->mti_magic = MDB_MAGIC; |
|
|
|
env->me_txns->mti_txnid = 0; |
|
|
|
env->me_txns->mti_txnid = 0; |
|
|
@ -3084,8 +3080,7 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl) |
|
|
|
rc = ErrCode(); |
|
|
|
rc = ErrCode(); |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#elif defined(MDB_USE_POSIX_SEM) |
|
|
|
#ifdef USE_POSIX_SEM |
|
|
|
|
|
|
|
env->me_rmutex = sem_open(env->me_txns->mti_rmname, 0); |
|
|
|
env->me_rmutex = sem_open(env->me_txns->mti_rmname, 0); |
|
|
|
if (env->me_rmutex == SEM_FAILED) { |
|
|
|
if (env->me_rmutex == SEM_FAILED) { |
|
|
|
rc = ErrCode(); |
|
|
|
rc = ErrCode(); |
|
|
@ -3271,8 +3266,7 @@ mdb_env_close(MDB_env *env) |
|
|
|
/* Windows automatically destroys the mutexes when
|
|
|
|
/* Windows automatically destroys the mutexes when
|
|
|
|
* the last handle closes. |
|
|
|
* the last handle closes. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#else |
|
|
|
#elif defined(MDB_USE_POSIX_SEM) |
|
|
|
#ifdef USE_POSIX_SEM |
|
|
|
|
|
|
|
sem_close(env->me_rmutex); |
|
|
|
sem_close(env->me_rmutex); |
|
|
|
sem_close(env->me_wmutex); |
|
|
|
sem_close(env->me_wmutex); |
|
|
|
{ int excl = 0; |
|
|
|
{ int excl = 0; |
|
|
@ -3283,7 +3277,6 @@ mdb_env_close(MDB_env *env) |
|
|
|
sem_unlink(env->me_txns->mti_wmname); |
|
|
|
sem_unlink(env->me_txns->mti_wmname); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
munmap((void *)env->me_txns, (env->me_maxreaders-1)*sizeof(MDB_reader)+sizeof(MDB_txninfo)); |
|
|
|
munmap((void *)env->me_txns, (env->me_maxreaders-1)*sizeof(MDB_reader)+sizeof(MDB_txninfo)); |
|
|
|
} |
|
|
|
} |
|
|
|