couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [02/50] couch commit: updated refs/heads/2080-port-cors-to-chttpd to 529339b
Date Tue, 02 Jun 2015 19:35:33 GMT
Assign waiter on return_proc in couch_proc_manager

There is a case when we return_proc while waiters exist. We should
assign returned proc to one of them. Effectively we unfreeze the waiter.

COUCHDB-2547


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/80f8330a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/80f8330a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/80f8330a

Branch: refs/heads/2080-port-cors-to-chttpd
Commit: 80f8330a8dd99c29f0bcc8d2d776ee04a54815b9
Parents: b59a4b2
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Wed Feb 4 13:25:45 2015 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Feb 10 11:06:44 2015 -0800

----------------------------------------------------------------------
 src/couch_proc_manager.erl | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/80f8330a/src/couch_proc_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_proc_manager.erl b/src/couch_proc_manager.erl
index f0fc6fa..20514cc 100644
--- a/src/couch_proc_manager.erl
+++ b/src/couch_proc_manager.erl
@@ -449,13 +449,23 @@ return_proc(#state{} = State, #proc_int{} = ProcInt) ->
                 true = ets:update_element(?PROCS, Pid, [
                     {#proc_int.client, undefined}
                 ]),
-                State
+                maybe_assign_proc(State, ProcInt)
         end;
     false ->
         remove_proc(State, ProcInt)
     end,
     flush_waiters(NewState, Lang).
 
+maybe_assign_proc(#state{} = State, ProcInt) ->
+    #proc_int{pid = Pid, lang = Lang} = ProcInt,
+    case get_waiting_client(Lang) of
+        #client{from = From} = Client ->
+            Proc = assign_proc(Client, ProcInt#proc_int{client=undefined}),
+            gen_server:reply(From, {ok, Proc, State#state.config}),
+            State;
+        undefined ->
+            State
+    end.
 
 remove_proc(State, #proc_int{}=Proc) ->
     ets:delete(?PROCS, Proc#proc_int.pid),


Mime
View raw message