Permalink
Browse files

Fix dialyzer make targets and dialyzer warnings.

Cleanup code to fit 80 char limit and -spec lines to be cleaner.
  • Loading branch information...
1 parent f9a1f32 commit c4b6c20a3090a78d2969433472c3e440678c3550 @bfrog committed Apr 17, 2012
Showing with 55 additions and 46 deletions.
  1. +1 −0 .gitignore
  2. +16 −16 Makefile
  3. +6 −5 src/hottub.erl
  4. +8 −6 src/ht_pool.erl
  5. +16 −13 src/ht_sup.erl
  6. +2 −2 src/ht_worker.erl
  7. +6 −4 src/ht_worker_sup.erl
View
@@ -21,3 +21,4 @@ rel/corbel
priv/machine.cfg
logs
log
+*.plt
View
@@ -1,48 +1,48 @@
-
.PHONY: all compile deps eunit rel clean
+PROJECT = hottub
+DIALYZER = dialyzer
+REBAR = rebar
+
all: compile
deps:
- @./rebar get-deps
+ @$(REBAR) get-deps
compile:
- @./rebar compile
+ @$(REBAR) compile
clean:
- @./rebar clean
+ @$(REBAR) clean
distclean: clean
- @./rebar delete-deps
+ @$(REBAR) delete-deps
docs:
- @./rebar skip_deps=true docs
+ @$(REBAR) skip_deps=true docs
APPS = kernel stdlib sasl erts ssl tools os_mon runtime_tools crypto inets \
xmerl webtool snmp public_key mnesia eunit syntax_tools compiler
-COMBO_PLT = $(HOME)/.corbel_dialyzer_plt
build_plt:
- dialyzer --build_plt --output_plt $(COMBO_PLT) --apps $(APPS) deps/*/ebin apps/*/ebin ebin
+ @$(DIALYZER) --build_plt --output_plt .$(PROJECT).plt \
+ --apps kernel stdlib sasl erts
dialyzer:
- @echo
- @echo Use "'make build_plt'" to build PLT prior to using this target.
- @echo
- @sleep 1
- dialyzer -Wno_return --plt $(COMBO_PLT) apps/*/ebin deps/*/ebin ebin
+ @$(DIALYZER) --plt .$(PROJECT).plt ebin --no_native \
+ -Wno_return -Werror_handling -Wrace_conditions -Wunmatched_returns
typer:
- typer --plt $(COMBO_PLT) -r apps -I deps -I apps
+ typer --plt .$(PROJECT).plt src
eunit:
rm -f .eunit/*.dat
- @./rebar skip_deps=true eunit
+ @$(REBAR) skip_deps=true eunit
test: eunit
rel: rel/reltool.config rel_clean all
- @./rebar generate
+ @$(REBAR) generate
rel_clean:
rm -rf rel/hottub
View
@@ -13,33 +13,34 @@
%% ----------------------------------------------------------------------------
%% @doc Start a linked hottub worker pool supervisor.
--spec start_link(PoolName::atom(), Limit::pos_integer(), M::module(), F::function(), A::list()) -> {ok, pid()}.
+-spec start_link(atom(), pos_integer(), atom(), atom(), list(any())) ->
+ ignore | {error, any()} | {ok, pid()}.
start_link(PoolName, Limit, Module, Function, Args) ->
ht_sup:start_link(PoolName, Limit, Module, Function, Args).
%% @doc Stop a hottub worker pool supervisor
--spec stop(PoolName::atom()) -> ok.
+-spec stop(atom()) -> ok.
stop(PoolName) ->
ht_sup:stop(PoolName).
%% @doc Perform a gen_server:call with a worker process.
--spec call(PoolName::atom(), Args::any()) -> Result::any().
+-spec call(atom(), any()) -> any().
call(PoolName, Args) ->
execute(PoolName,
fun(Worker) ->
gen_server:call(Worker, Args)
end).
%% @doc Perform a gen_server:call with a worker process.
--spec cast(PoolName::atom(), Args::any()) -> Result::any().
+-spec cast(atom(), any()) -> any().
cast(PoolName, Args) ->
execute(PoolName,
fun(Worker) ->
gen_server:cast(Worker, Args)
end).
%% @doc Execute a function using a worker.
--spec execute(PoolName::atom(), Function::fun((Worker::pid()) -> Result::any())) -> Result::any().
+-spec execute(atom(), fun((pid()) -> any())) -> any().
execute(PoolName, Function) ->
Worker = ht_pool:checkout_worker(PoolName),
try
View
@@ -26,7 +26,8 @@
-export([start_link/1, add_worker/2, checkout_worker/1, checkin_worker/2]).
%% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
+ code_change/3]).
-record(state, {poolname=undefined, unused=queue:new(), checkouts=queue:new()}).
@@ -36,17 +37,17 @@
%% ----------------------------------------------------------------------------
%% @doc Start a linked pool manager.
--spec start_link(PoolName::atom()) -> {ok, pid()}.
+-spec start_link(atom()) -> {ok, pid()}.
start_link(PoolName) ->
gen_server:start_link({local, PoolName}, ?MODULE, [PoolName], []).
%% @doc Called by ht_worker after the worker process has started.
--spec add_worker(PoolName::atom(), Pid::pid()) -> term().
+-spec add_worker(atom(), pid()) -> term().
add_worker(PoolName, Pid) ->
gen_server:cast(PoolName, {add_worker, Pid}).
%% @doc Checkin a worker.
--spec checkin_worker(PoolName::atom(), Pid::pid()) -> term().
+-spec checkin_worker(atom(), pid()) -> term().
checkin_worker(PoolName, Pid) when is_pid(Pid) ->
%% try to avoid a dead worker getting checked in needlessly
case is_process_alive(Pid) of
@@ -57,7 +58,7 @@ checkin_worker(PoolName, Pid) when is_pid(Pid) ->
end.
%% @doc Checkout a worker.
--spec checkout_worker(PoolName::atom()) -> Worker::pid() | undefined.
+-spec checkout_worker(atom()) -> pid() | undefined.
checkout_worker(PoolName) ->
Worker = gen_server:call(PoolName, {checkout_worker}),
%% try to avoid a dead worker getting checked out causing headaches
@@ -110,7 +111,8 @@ handle_cast({add_worker, Worker}, State) ->
%% @private
handle_info({'DOWN', _, _, Worker, _}, State) ->
- Unused = queue:from_list(lists:delete(Worker, queue:to_list(State#state.unused))),
+ Unused = queue:from_list(lists:delete(Worker,
+ queue:to_list(State#state.unused))),
{noreply, State#state{unused=Unused}}.
%% @private
View
@@ -18,22 +18,27 @@
%% ----------------------------------------------------------------------------
%% @doc Start linked hottub supervisor.
--spec start_link(PoolName::string(), Limit::pos_integer(), Module::module(),
- Function::function(), Arguments::list()) -> {ok, Sup::pid()}.
-start_link(PoolName, Limit, Module, Function, Arguments) ->
+-spec start_link(atom(), pos_integer(), atom(), atom(), list(any())) ->
+ ignore | {error, term()} | {ok, pid()}.
+start_link(PoolName, Limit, Module, Function, Arguments) when
+ is_atom(PoolName),
+ is_integer(Limit),
+ is_atom(Module),
+ is_atom(Function),
+ is_list(Arguments) ->
supervisor:start_link({local, sup_name(PoolName)}, ?MODULE,
[PoolName, Limit, Module, Function, Arguments]).
%% @doc Stop a hottub supervisor.
--spec stop(PoolName::string()) -> ok.
+-spec stop(atom()) -> ok.
stop(PoolName) ->
SupName = sup_name(PoolName),
- Pid = whereis(SupName),
- unlink(Pid),
- Ref = monitor(process, Pid),
- IsPid = is_pid(Pid),
- case IsPid of
- true ->
+ case whereis(SupName) of
+ undefined ->
+ ok;
+ Pid ->
+ unlink(Pid),
+ Ref = monitor(process, Pid),
exit(Pid, shutdown),
receive
{'DOWN', Ref, process, Pid, shutdown} ->
@@ -42,9 +47,7 @@ stop(PoolName) ->
1000 ->
erlang:exit(Pid, kill),
ok
- end;
- false ->
- ok
+ end
end.
%% ----------------------------------------------------------------------------
View
@@ -11,8 +11,8 @@
%% supervisor calls to start a process with another that does some additional
%% work.
%% @end
--spec start_worker(atom(), {module(), function(), list()})
- -> {ok, Pid::pid()}.
+-spec start_worker(atom(), {atom(), atom(), list(any())})
+ -> {ok, pid()}.
start_worker(PoolName, {Module, Function, Arguments}) ->
{ok, Pid} = erlang:apply(Module, Function, Arguments),
ht_pool:add_worker(PoolName, Pid),
View
@@ -18,10 +18,11 @@
%% ----------------------------------------------------------------------------
%% @doc Start linked hot tub worker supervisor.
--spec start_link(PoolName::atom(), Limit::pos_integer(), Module::module(),
- Function::function(), Arguments::list()) -> {ok, Sup::pid()}.
+-spec start_link(atom(), pos_integer(), atom(), atom(), list(any())) ->
+ {ok, pid()}.
start_link(PoolName, Limit, Module, Function, Arguments) ->
- supervisor:start_link({local, sup_name(PoolName)}, ?MODULE, [PoolName, Limit, Module, Function, Arguments]).
+ supervisor:start_link({local, sup_name(PoolName)}, ?MODULE,
+ [PoolName, Limit, Module, Function, Arguments]).
%% ----------------------------------------------------------------------------
@@ -32,7 +33,8 @@ sup_name(PoolName) ->
list_to_atom(atom_to_list(PoolName) ++ "_worker_sup").
worker_name(PoolName, Id) ->
- lists:flatten([atom_to_list(PoolName) | ["_worker_" | io_lib:format("~p", [Id])]]).
+ lists:flatten([atom_to_list(PoolName) | ["_worker_"
+ | io_lib:format("~p", [Id])]]).
%% ----------------------------------------------------------------------------

0 comments on commit c4b6c20

Please sign in to comment.