HANDLE me_mfd; /**< just for writing the meta pages */
/** Failed to update the meta page. Probably an I/O error. */
#define MDB_FATAL_ERROR 0x80000000U
- /** Read-only Filesystem. Allow read access, no locking. */
-#define MDB_ROFS 0x40000000U
/** Some fields are initialized. */
#define MDB_ENV_ACTIVE 0x20000000U
+ /** me_txkey is set */
+#define MDB_ENV_TXKEY 0x10000000U
uint32_t me_flags; /**< @ref mdb_env */
unsigned int me_psize; /**< size of a page, from #GET_PAGESIZE */
unsigned int me_maxreaders; /**< size of the reader table */
txn->mt_dbxs = env->me_dbxs; /* mostly static anyway */
if (txn->mt_flags & MDB_TXN_RDONLY) {
- if (env->me_flags & MDB_ROFS) {
+ if (!env->me_txns) {
i = mdb_env_pick_meta(env);
txn->mt_txnid = env->me_metas[i]->mm_txnid;
txn->mt_u.reader = NULL;
}
if (F_ISSET(txn->mt_flags, MDB_TXN_RDONLY)) {
- if (!(env->me_flags & MDB_ROFS))
+ if (txn->mt_u.reader) {
txn->mt_u.reader->mr_txnid = (txnid_t)-1;
+ }
} else {
MDB_page *dp;
return ENOMEM;
e->me_maxreaders = DEFAULT_READERS;
- e->me_maxdbs = 2;
+ e->me_maxdbs = e->me_numdbs = 2;
e->me_fd = INVALID_HANDLE_VALUE;
e->me_lfd = INVALID_HANDLE_VALUE;
e->me_mfd = INVALID_HANDLE_VALUE;
if (env->me_lfd == INVALID_HANDLE_VALUE) {
rc = ErrCode();
if (rc == MDB_ERRCODE_ROFS && (env->me_flags & MDB_RDONLY)) {
- env->me_flags |= MDB_ROFS;
return MDB_SUCCESS;
}
goto fail_errno;
fcntl(env->me_lfd, F_SETFD, fdflags);
#endif
+ {
+ rc = pthread_key_create(&env->me_txkey, mdb_env_reader_dest);
+ if (rc)
+ goto fail;
+ env->me_flags |= MDB_ENV_TXKEY;
+#ifdef _WIN32
+ /* Windows TLS callbacks need help finding their TLS info. */
+ if (mdb_tls_nkeys >= MAX_TLS_KEYS) {
+ rc = MDB_TLS_FULL;
+ goto fail;
+ }
+ mdb_tls_keys[mdb_tls_nkeys++] = env->me_txkey;
+#endif
+ }
+
/* Try to get exclusive lock. If we succeed, then
* nobody is using the lock region and we should initialize it.
*/
}
}
DPRINTF("opened dbenv %p", (void *) env);
- rc = pthread_key_create(&env->me_txkey, mdb_env_reader_dest);
- if (rc)
- goto leave;
- env->me_numdbs = 2; /* this notes that me_txkey was set */
-#ifdef _WIN32
- /* Windows TLS callbacks need help finding their TLS info. */
- if (mdb_tls_nkeys < MAX_TLS_KEYS)
- mdb_tls_keys[mdb_tls_nkeys++] = env->me_txkey;
- else {
- rc = MDB_TLS_FULL;
- goto leave;
- }
-#endif
if (excl > 0) {
rc = mdb_env_share_locks(env, &excl);
}
if (env->me_free_pgs)
mdb_midl_free(env->me_free_pgs);
- if (env->me_numdbs) {
+ if (env->me_flags & MDB_ENV_TXKEY) {
pthread_key_delete(env->me_txkey);
#ifdef _WIN32
/* Delete our key from the global list */
close(env->me_lfd);
}
- env->me_flags &= ~MDB_ENV_ACTIVE;
+ env->me_flags &= ~(MDB_ENV_ACTIVE|MDB_ENV_TXKEY);
}
int
if (rc)
goto leave;
- if (!(env->me_flags & MDB_ROFS)) {
+ if (env->me_txns) {
/* We must start the actual read txn after blocking writers */
mdb_txn_reset0(txn);
rc = write(newfd, env->me_map, wsize);
rc = (rc == (int)wsize) ? MDB_SUCCESS : ErrCode();
#endif
- if (! (env->me_flags & MDB_ROFS))
+ if (env->me_txns)
UNLOCK_MUTEX_W(env);
if (rc)