Added flags to the close_database function.

This commit is contained in:
Phillip Toland 2008-12-10 12:58:54 -06:00
parent d2f15bef80
commit cf6ef4d296
2 changed files with 18 additions and 8 deletions

View file

@ -17,8 +17,8 @@
/** /**
* Function prototypes * Function prototypes
*/ */
static int open_database(const char* name, DBTYPE type, unsigned int flags, PortData* data, int* errno); static int open_database(const char* name, DBTYPE type, unsigned flags, PortData* data, int* errno);
static int close_database(int dbref, PortData* data); static int close_database(int dbref, unsigned flags, PortData* data);
static void do_async_put(void* arg); static void do_async_put(void* arg);
static void do_async_put_free(void* arg); static void do_async_put_free(void* arg);
@ -182,7 +182,7 @@ static void bdberl_drv_stop(ErlDrvData handle)
// Close all the databases we previously opened // Close all the databases we previously opened
while (d->dbrefs) while (d->dbrefs)
{ {
close_database(d->dbrefs->dbref, d); close_database(d->dbrefs->dbref, 0, d);
} }
// Release the port instance data // Release the port instance data
@ -210,7 +210,7 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd,
case CMD_OPEN_DB: case CMD_OPEN_DB:
{ {
// Extract the type code and filename from the inbuf // Extract the type code and filename from the inbuf
// Inbuf is: <<Flags:32, Type:8, Name/bytes, 0:8>> // Inbuf is: <<Flags:32/unsigned, Type:8, Name/bytes, 0:8>>
unsigned flags = (unsigned) DECODE_INT(inbuf, 0); unsigned flags = (unsigned) DECODE_INT(inbuf, 0);
DBTYPE type = (DBTYPE) DECODE_BYTE(inbuf, 4); DBTYPE type = (DBTYPE) DECODE_BYTE(inbuf, 4);
char* name = DECODE_STRING(inbuf, 5); char* name = DECODE_STRING(inbuf, 5);
@ -240,8 +240,11 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd,
// TODO: If data is inflight, fail. Abort any open txns. // TODO: If data is inflight, fail. Abort any open txns.
// Take the provided dbref and attempt to close it // Take the provided dbref and attempt to close it
// Inbuf is: <<DbRef:32, Flags:32/unsigned>>
int dbref = DECODE_INT(inbuf, 0); int dbref = DECODE_INT(inbuf, 0);
int rc = close_database(dbref, d); unsigned flags = (unsigned) DECODE_INT(inbuf, 4);
int rc = close_database(dbref, flags, d);
// Outbuf is: <<Rc:32>> // Outbuf is: <<Rc:32>>
RETURN_INT(rc, outbuf); RETURN_INT(rc, outbuf);
@ -538,7 +541,7 @@ static int open_database(const char* name, DBTYPE type, unsigned int flags, Port
} }
} }
static int close_database(int dbref, PortData* data) static int close_database(int dbref, unsigned flags, PortData* data)
{ {
printf("Closing %d for port %p\n", dbref, data->port); printf("Closing %d for port %p\n", dbref, data->port);
@ -562,7 +565,7 @@ static int close_database(int dbref, PortData* data)
{ {
printf("Closing actual database for dbref %d\n", dbref); printf("Closing actual database for dbref %d\n", dbref);
// Close out the BDB handle // Close out the BDB handle
database->db->close(database->db, 0); database->db->close(database->db, flags);
// Remove the entry from the names map // Remove the entry from the names map
hive_hash_remove(G_DATABASES_NAMES, database->name); hive_hash_remove(G_DATABASES_NAMES, database->name);

View file

@ -36,6 +36,8 @@
-define(DB_THREAD, 16#00000004). -define(DB_THREAD, 16#00000004).
-define(DB_TRUNCATE, 16#00008000). -define(DB_TRUNCATE, 16#00008000).
-define(DB_NOSYNC, 21).
-define(STATUS_OK, 0). -define(STATUS_OK, 0).
-define(STATUS_ERROR, 1). -define(STATUS_ERROR, 1).
@ -73,7 +75,11 @@ open_database(Port, Name, Type, Opts) ->
end. end.
close_database(Port, DbRef) -> close_database(Port, DbRef) ->
Cmd = <<DbRef:32/native-integer>>, close_database(Port, DbRef, []).
close_database(Port, DbRef, Opts) ->
Flags = process_flags(Opts),
Cmd = <<DbRef:32/native-integer, Flags:32/unsigned-native-integer>>,
case erlang:port_control(Port, ?CMD_CLOSE_DB, Cmd) of case erlang:port_control(Port, ?CMD_CLOSE_DB, Cmd) of
<<0:32/native-integer>> -> <<0:32/native-integer>> ->
{error, invalid_dbref}; {error, invalid_dbref};
@ -165,6 +171,7 @@ flag_value(Flag) ->
exclusive -> ?DB_EXCL; exclusive -> ?DB_EXCL;
multiversion -> ?DB_MULTIVERSION; multiversion -> ?DB_MULTIVERSION;
no_mmap -> ?DB_NOMMAP; no_mmap -> ?DB_NOMMAP;
no_sync -> ?DB_NOSYNC;
readonly -> ?DB_RDONLY; readonly -> ?DB_RDONLY;
threaded -> ?DB_THREAD; threaded -> ?DB_THREAD;
truncate -> ?DB_TRUNCATE truncate -> ?DB_TRUNCATE