summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_ref_counter.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/couchdb/couch_ref_counter.erl')
-rw-r--r--src/couchdb/couch_ref_counter.erl41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/couchdb/couch_ref_counter.erl b/src/couchdb/couch_ref_counter.erl
index 96d92333..5a111ab6 100644
--- a/src/couchdb/couch_ref_counter.erl
+++ b/src/couchdb/couch_ref_counter.erl
@@ -24,7 +24,7 @@ drop(RefCounterPid) ->
drop(RefCounterPid, self()).
drop(RefCounterPid, Pid) ->
- gen_server:cast(RefCounterPid, {drop, Pid}).
+ gen_server:call(RefCounterPid, {drop, Pid}).
add(RefCounterPid) ->
@@ -66,10 +66,8 @@ handle_call({add, Pid},_From, #srv{referrers=Referrers}=Srv) ->
{reply, ok, Srv#srv{referrers=Referrers2}};
handle_call(count, _From, Srv) ->
{monitors, Monitors} = process_info(self(), monitors),
- {reply, length(Monitors), Srv}.
-
-
-handle_cast({drop, Pid}, #srv{referrers=Referrers}=Srv) ->
+ {reply, length(Monitors), Srv};
+handle_call({drop, Pid}, _From, #srv{referrers=Referrers}=Srv) ->
Referrers2 =
case dict:find(Pid, Referrers) of
{ok, {MonRef, 1}} ->
@@ -80,7 +78,16 @@ handle_cast({drop, Pid}, #srv{referrers=Referrers}=Srv) ->
error ->
Referrers
end,
- maybe_close_async(Srv#srv{referrers=Referrers2}).
+ Srv2 = Srv#srv{referrers=Referrers2},
+ case should_close() of
+ true ->
+ {stop,normal,ok,Srv2};
+ false ->
+ {reply, ok, Srv2}
+ end.
+
+handle_cast(Msg, _Srv)->
+ exit({unknown_msg,Msg}).
code_change(_OldVsn, State, _Extra) ->
@@ -88,21 +95,17 @@ code_change(_OldVsn, State, _Extra) ->
handle_info({'DOWN', MonRef, _, Pid, _}, #srv{referrers=Referrers}=Srv) ->
{ok, {MonRef, _RefCount}} = dict:find(Pid, Referrers),
- maybe_close_async(Srv#srv{referrers=dict:erase(Pid, Referrers)}).
+ Srv2 = Srv#srv{referrers=dict:erase(Pid, Referrers)},
+ case should_close() of
+ true ->
+ {stop,normal,Srv2};
+ false ->
+ {noreply,Srv2}
+ end.
should_close() ->
case process_info(self(), monitors) of
- {monitors, []} ->
- true;
- _ ->
- false
- end.
-
-maybe_close_async(Srv) ->
- case should_close() of
- true ->
- {stop,normal,Srv};
- false ->
- {noreply,Srv}
+ {monitors, []} -> true;
+ _ -> false
end.