tmgrp->mem = &txn_regionp[1]; tmgrp->mutexp = NULL;
txn_open(path, flags, mode, dbenv, mgrpp)	const char *path;	int flags, mode;	DB_ENV *dbenv;	DB_TXNMGR **mgrpp;{	DB_TXNMGR *tmgrp;	DB_TXNREGION *txn_regionp;	int fd, ret, retry_cnt;	tmgrp = NULL;	txn_regionp = NULL;	fd = -1;	/* Validate arguments. */	if (dbenv == NULL)		return (EINVAL);#ifdef HAVE_SPINLOCKS#define	OKFLAGS	(DB_CREATE | DB_THREAD | DB_TXN_NOSYNC)#else#define	OKFLAGS	(DB_CREATE | DB_TXN_NOSYNC)#endif	if ((ret = __db_fchk(dbenv, "txn_open", flags, OKFLAGS)) != 0)		return (ret);	retry_cnt = 0;retry:	if (LF_ISSET(DB_CREATE) && (ret = __txn_create(dbenv, path, mode)) != 0)		if (ret == EAGAIN && ++retry_cnt < 0) {			(void)__db_sleep(1, 0);			goto retry;		} else	/* We did not really create the region */			flags &= ~DB_CREATE;	retry_cnt = 0;retry1:	if ((ret = __db_ropen(dbenv, DB_APP_NONE, path, DEFAULT_TXN_FILE,	    flags & ~(DB_CREATE | DB_THREAD | DB_TXN_NOSYNC),	    &fd, &txn_regionp)) != 0) {		if (ret == EAGAIN && ++retry_cnt < 3) {			(void)__db_sleep(1, 0);			goto retry1;		}		goto out;	}	/* Check if valid region. */	if (txn_regionp->magic != DB_TXNMAGIC) {		__db_err(dbenv, "txn_open: Bad magic number");		ret = EINVAL;		goto out;	}	/* Now, create the transaction manager structure and set its fields. */	if ((tmgrp = (DB_TXNMGR *)__db_malloc(sizeof(DB_TXNMGR))) == NULL) {		__db_err(dbenv, "txn_open: %s", strerror(ENOMEM));		ret = ENOMEM;		goto out;	}	tmgrp->dbenv = dbenv;	tmgrp->recover =	    dbenv->tx_recover == NULL ? __db_dispatch : dbenv->tx_recover;	tmgrp->region = txn_regionp;	tmgrp->reg_size = txn_regionp->hdr.size;	tmgrp->fd = fd;	tmgrp->flags = LF_ISSET(DB_TXN_NOSYNC | DB_THREAD);	tmgrp->mem = &txn_regionp[1];	tmgrp->mutexp = NULL;	TAILQ_INIT(&tmgrp->txn_chain);	if (LF_ISSET(DB_THREAD)) {		LOCK_TXNREGION(tmgrp);		if ((ret = __db_shalloc(tmgrp->mem, sizeof(db_mutex_t),		    MUTEX_ALIGNMENT, &tmgrp->mutexp)) == 0)			/*			 * Since we only get here if threading is turned on, we			 * know that we have spinlocks, so the offset is going			 * to be ignored.  We put 0 here as a valid placeholder.			 */			__db_mutex_init(tmgrp->mutexp, 0);		UNLOCK_TXNREGION(tmgrp);		if (ret != 0)			goto out;	}	*mgrpp = tmgrp;	return (0);out:	if (txn_regionp != NULL)		(void)__db_rclose(dbenv, fd, txn_regionp);	if (flags & DB_CREATE)		(void)txn_unlink(path, 1, dbenv);	if (tmgrp != NULL) {		if (tmgrp->mutexp != NULL) {			LOCK_TXNREGION(tmgrp);			__db_shalloc_free(tmgrp->mem, tmgrp->mutexp);			UNLOCK_TXNREGION(tmgrp);		}		__db_free(tmgrp);	}	return (ret);}