Example #1
0
File: txn.go Project: Crest/gomdb
func (env *Env) BeginTxn(parent *Txn, flags uint) (*Txn, error) {
	var _txn *C.MDB_txn
	var ptxn *C.MDB_txn
	if parent == nil {
		ptxn = nil
	} else {
		ptxn = parent._txn
	}
	ret := C.mdb_txn_begin(env._env, ptxn, C.uint(flags), &_txn)
	if ret != SUCCESS {
		return nil, Errno(ret)
	}
	return &Txn{_txn}, nil
}
Example #2
0
File: txn.go Project: postfix/gomdb
func (env *Env) BeginTxn(parent *Txn, flags uint) (*Txn, error) {
	var _txn *C.MDB_txn
	var ptxn *C.MDB_txn
	if parent == nil {
		ptxn = nil
	} else {
		ptxn = parent._txn
	}
	if flags&RDONLY == 0 {
		runtime.LockOSThread()
	}
	ret := C.mdb_txn_begin(env._env, ptxn, C.uint(flags), &_txn)
	if ret != SUCCESS {
		runtime.UnlockOSThread()
		return nil, Errno(ret)
	}
	return &Txn{_txn}, nil
}
Example #3
0
// beginTxn does not lock the OS thread which is a prerequisite for creating a
// write transaction.
func beginTxn(env *Env, parent *Txn, flags uint) (*Txn, error) {
	txn := &Txn{
		readonly: (flags&Readonly != 0),
		env:      env,
	}

	var ptxn *C.MDB_txn
	if parent == nil {
		ptxn = nil
		txn.key = new(C.MDB_val)
		txn.val = new(C.MDB_val)
	} else {
		ptxn = parent._txn
		txn.key = parent.key
		txn.val = parent.val
	}
	ret := C.mdb_txn_begin(env._env, ptxn, C.uint(flags), &txn._txn)
	if ret != success {
		return nil, operrno("mdb_txn_begin", ret)
	}
	return txn, nil
}
Example #4
0
File: txn.go Project: hughe/gomdb
// BeginTxn wraps mdb_txn_begin. http://goo.gl/KoSCV1
//
// BUG: Due to the nature of Go and the lightweight nature of the gomdb API all
// operations on the returned transaction must be made within the caller's
// goroutine to ensure operations are serialized on the same OS thread.  This
// same-goroutine restriction also applies to the creation of nested
// transactions.
func (env *Env) BeginTxn(parent *Txn, flags uint) (*Txn, error) {
	var _txn *C.MDB_txn
	var ptxn *C.MDB_txn
	var nested bool
	if parent == nil {
		ptxn = nil
	} else {
		nested = true
		ptxn = parent._txn
	}
	// top-level writable transactions must be serialized on an os thread.
	if !nested && flags&RDONLY == 0 {
		runtime.LockOSThread()
	}

	ret := C.mdb_txn_begin(env._env, ptxn, C.uint(flags), &_txn)
	if ret != SUCCESS {
		runtime.UnlockOSThread()
		return nil, errno(ret)
	}

	txn := &Txn{_txn, nested}
	return txn, nil
}