Save pid in MDB_env instead of repeating getpid().

An open MDB environment does not survive or catch fork(),
so repeating getpid() was pointless.
vmware
Hallvard Furuseth 12 years ago
parent 20a216fcc9
commit 38cc1e96b4
  1. 6
      libraries/libmdb/mdb.c

@ -906,6 +906,7 @@ struct MDB_env {
unsigned int me_maxreaders; /**< size of the reader table */ unsigned int me_maxreaders; /**< size of the reader table */
MDB_dbi me_numdbs; /**< number of DBs opened */ MDB_dbi me_numdbs; /**< number of DBs opened */
MDB_dbi me_maxdbs; /**< size of the DB table */ MDB_dbi me_maxdbs; /**< size of the DB table */
pid_t me_pid; /**< process ID of this env */
char *me_path; /**< path to the DB files */ char *me_path; /**< path to the DB files */
char *me_map; /**< the memory map of the data file */ char *me_map; /**< the memory map of the data file */
MDB_txninfo *me_txns; /**< the memory map of the lock file */ MDB_txninfo *me_txns; /**< the memory map of the lock file */
@ -1625,7 +1626,7 @@ mdb_txn_renew0(MDB_txn *txn)
if (txn->mt_flags & MDB_TXN_RDONLY) { if (txn->mt_flags & MDB_TXN_RDONLY) {
MDB_reader *r = pthread_getspecific(env->me_txkey); MDB_reader *r = pthread_getspecific(env->me_txkey);
if (!r) { if (!r) {
pid_t pid = getpid(); pid_t pid = env->me_pid;
pthread_t tid = pthread_self(); pthread_t tid = pthread_self();
LOCK_MUTEX_R(env); LOCK_MUTEX_R(env);
@ -2506,6 +2507,7 @@ mdb_env_create(MDB_env **env)
e->me_fd = INVALID_HANDLE_VALUE; e->me_fd = INVALID_HANDLE_VALUE;
e->me_lfd = INVALID_HANDLE_VALUE; e->me_lfd = INVALID_HANDLE_VALUE;
e->me_mfd = INVALID_HANDLE_VALUE; e->me_mfd = INVALID_HANDLE_VALUE;
e->me_pid = getpid();
VGMEMP_CREATE(e,0,0); VGMEMP_CREATE(e,0,0);
*env = e; *env = e;
return MDB_SUCCESS; return MDB_SUCCESS;
@ -3255,7 +3257,7 @@ mdb_env_close(MDB_env *env)
close(env->me_mfd); close(env->me_mfd);
close(env->me_fd); close(env->me_fd);
if (env->me_txns) { if (env->me_txns) {
pid_t pid = getpid(); pid_t pid = env->me_pid;
unsigned int i; unsigned int i;
for (i=0; i<env->me_txns->mti_numreaders; i++) for (i=0; i<env->me_txns->mti_numreaders; i++)
if (env->me_txns->mti_readers[i].mr_pid == pid) if (env->me_txns->mti_readers[i].mr_pid == pid)

Loading…
Cancel
Save