Add spawn_opt option for open and open_link.

Typically used to specify non-default, garbage collection options.
This commit is contained in:
Joseph Wayne Norton 2012-09-25 15:15:37 +09:00
parent 1bbea4b87d
commit 4023ecf013
2 changed files with 13 additions and 6 deletions

View file

@ -69,6 +69,7 @@
| {merge_strategy, fast | predictable }
| {sync_strategy, none | sync | {seconds, pos_integer()}}
| {expiry_secs, non_neg_integer()}
| {spawn_opt, list()}
.
%% @doc
@ -83,14 +84,16 @@ open(Dir) ->
- spec open(Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open(Dir, Opts) ->
ok = start_app(),
gen_server:start(?MODULE, [Dir, Opts], []).
SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
gen_server:start(?MODULE, [Dir, Opts], [{spawn_opt,SpawnOpt}]).
%% @doc Create or open a hanoidb store with a registered name.
- spec open(Name::{local, Name::atom()} | {global, GlobalName::term()} | {via, ViaName::term()},
Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open(Name, Dir, Opts) ->
ok = start_app(),
gen_server:start(Name, ?MODULE, [Dir, Opts], []).
SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
gen_server:start(Name, ?MODULE, [Dir, Opts], [{spawn_opt,SpawnOpt}]).
%% @doc
%% Create or open a hanoidb store as part of a supervision tree.
@ -105,7 +108,8 @@ open_link(Dir) ->
- spec open_link(Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open_link(Dir, Opts) ->
ok = start_app(),
gen_server:start_link(?MODULE, [Dir, Opts], []).
SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
gen_server:start_link(?MODULE, [Dir, Opts], [{spawn_opt,SpawnOpt}]).
%% @doc Create or open a hanoidb store as part of a supervision tree
%% with a registered name.
@ -113,7 +117,8 @@ open_link(Dir, Opts) ->
Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open_link(Name, Dir, Opts) ->
ok = start_app(),
gen_server:start_link(Name, ?MODULE, [Dir, Opts], []).
SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
gen_server:start_link(Name, ?MODULE, [Dir, Opts], [{spawn_opt,SpawnOpt}]).
%% @doc
%% Close a Hanoi data store.

View file

@ -80,12 +80,14 @@ debug_log(State,Fmt,Args) ->
open(Dir,Level,Next,Opts,Owner) when Level>0 ->
hanoidb_util:ensure_expiry(Opts),
PID = plain_fsm:spawn(?MODULE,
SpawnOpt = hanoidb:get_opt(spawn_opt, Opts, []),
PID = plain_fsm:spawn_opt(?MODULE,
fun() ->
process_flag(trap_exit,true),
link(Owner),
initialize(#state{dir=Dir,level=Level,next=Next,opts=Opts,owner=Owner})
end),
end,
SpawnOpt),
{ok, PID}.
lookup(Ref, Key) ->