From f743d855d8470cced43eeea49c0963a86b2f5131 Mon Sep 17 00:00:00 2001 From: Phillip Toland Date: Wed, 10 Dec 2008 17:05:08 -0600 Subject: [PATCH] Added flags for txn_begin function. --- c_src/bdberl_drv.c | 7 +++++-- src/bdberl_port.erl | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/c_src/bdberl_drv.c b/c_src/bdberl_drv.c index ee95c8b..1e40888 100644 --- a/c_src/bdberl_drv.c +++ b/c_src/bdberl_drv.c @@ -212,7 +212,7 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd, { // Extract the type code and filename from the inbuf // Inbuf is: <> - unsigned flags = (unsigned) UNPACK_INT(inbuf, 0); + unsigned flags = UNPACK_INT(inbuf, 0); DBTYPE type = (DBTYPE) UNPACK_BYTE(inbuf, 4); char* name = UNPACK_STRING(inbuf, 5); int dbref; @@ -264,8 +264,11 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd, RETURN_INT(ERROR_TXN_OPEN, outbuf); } + // Inbuf is <> + unsigned flags = UNPACK_INT(inbuf, 0); + // Outbuf is <> - int rc = G_DB_ENV->txn_begin(G_DB_ENV, 0, &(d->txn), 0); + int rc = G_DB_ENV->txn_begin(G_DB_ENV, 0, &(d->txn), flags); RETURN_INT(rc, outbuf); } case CMD_TXN_COMMIT: diff --git a/src/bdberl_port.erl b/src/bdberl_port.erl index 2e02eda..8ff421a 100644 --- a/src/bdberl_port.erl +++ b/src/bdberl_port.erl @@ -287,7 +287,12 @@ close_database(Port, DbRef, Opts) -> end. txn_begin(Port) -> - <> = erlang:port_control(Port, ?CMD_TXN_BEGIN, <<>>), + txn_begin(Port, []). + +txn_begin(Port, Opts) -> + Flags = process_flags(Opts), + Cmd = <>, + <> = erlang:port_control(Port, ?CMD_TXN_BEGIN, Cmd), case Result of ?ERROR_NONE -> ok; ?ERROR_ASYNC_PENDING -> {error, async_pending}; @@ -388,5 +393,11 @@ flag_value(Flag) -> rmw -> ?DB_RMW; set_recno -> ?DB_SET_RECNO; threaded -> ?DB_THREAD; - truncate -> ?DB_TRUNCATE + truncate -> ?DB_TRUNCATE; + txn_no_sync -> ?DB_TXN_NOSYNC; + txn_no_wait -> ?DB_TXN_NOWAIT; + txn_snapshot -> ?DB_TXN_SNAPSHOT; + txn_sync -> ?DB_TXN_SYNC; + txn_wait -> ?DB_TXN_WAIT; + txn_write_nosync -> ?DB_TXN_WRITE_NOSYNC end.