Make init/0 private and rely on lazy initialization.

This commit is contained in:
Phillip Toland 2008-12-12 12:47:25 -06:00
parent 5f2b99554a
commit f71dd191f2
2 changed files with 13 additions and 23 deletions

View file

@ -6,8 +6,7 @@
%% -------------------------------------------------------------------
-module(bdberl).
-export([init/0,
open/2, open/3,
-export([open/2, open/3,
close/1, close/2,
txn_begin/0, txn_begin/1,
txn_commit/0, txn_commit/1, txn_abort/0,
@ -20,14 +19,6 @@
-include("bdberl.hrl").
init() ->
case erl_ddll:load_driver(code:priv_dir(bdberl), bdberl_drv) of
ok -> ok;
{error, permanent} -> ok % Means that the driver is already active
end,
Port = open_port({spawn, bdberl_drv}, [binary]),
erlang:put(bdb_port, Port),
ok.
open(Name, Type) ->
open(Name, Type, [create]).
@ -210,14 +201,20 @@ set_txn_timeout(Timeout) ->
%% Internal functions
%% ====================================================================
init() ->
case erl_ddll:load_driver(code:priv_dir(bdberl), bdberl_drv) of
ok -> ok;
{error, permanent} -> ok % Means that the driver is already active
end,
Port = open_port({spawn, bdberl_drv}, [binary]),
erlang:put(bdb_port, Port),
Port.
get_port() ->
case erlang:get(bdb_port) of
undefined ->
ok = init(),
erlang:get(bdb_port);
Port ->
Port
end.
undefined -> init();
Port -> Port
end.
%%
%% Decode a integer return value into an atom representation

View file

@ -20,13 +20,6 @@ all() ->
update_should_save_value_if_successful].
init_per_suite(Config) ->
ok = bdberl:init(),
Config.
end_per_suite(_Config) ->
ok.
init_per_testcase(_TestCase, Config) ->
{ok, Db} = bdberl:open("api_test.db", btree, [create, exclusive]),
[{db, Db}|Config].