diff options
| author | Matthias Radestock <matthias@lshift.net> | 2009-03-12 18:13:52 +0000 |
|---|---|---|
| committer | Matthias Radestock <matthias@lshift.net> | 2009-03-12 18:13:52 +0000 |
| commit | c44b6f17330915eb439cf24bcdbba1756604eca0 (patch) | |
| tree | 305de7643458ce1ab6740d77616cd297a29f7971 /src | |
| parent | c61c5144f675d9c23c7ed738d65ec57a04c5da5e (diff) | |
| download | rabbitmq-server-git-c44b6f17330915eb439cf24bcdbba1756604eca0.tar.gz | |
fix bug
Diffstat (limited to 'src')
| -rw-r--r-- | src/gen_server2.erl | 49 | ||||
| -rw-r--r-- | src/priority_queue.erl | 3 |
2 files changed, 46 insertions, 6 deletions
diff --git a/src/gen_server2.erl b/src/gen_server2.erl index fbaff765d9..11ac7987a3 100644 --- a/src/gen_server2.erl +++ b/src/gen_server2.erl @@ -107,8 +107,8 @@ %% API -export([start/3, start/4, start_link/3, start_link/4, - call/2, call/3, - cast/2, reply/2, + call/2, call/3, pcall/3, pcall/4, + cast/2, pcast/3, reply/2, abcast/2, abcast/3, multi_call/2, multi_call/3, multi_call/4, enter_loop/3, enter_loop/4, enter_loop/5]). @@ -188,6 +188,22 @@ call(Name, Request, Timeout) -> exit({Reason, {?MODULE, call, [Name, Request, Timeout]}}) end. +pcall(Name, Priority, Request) -> + case catch gen:call(Name, '$gen_pcall', {Priority, Request}) of + {ok,Res} -> + Res; + {'EXIT',Reason} -> + exit({Reason, {?MODULE, pcall, [Name, Priority, Request]}}) + end. + +pcall(Name, Priority, Request, Timeout) -> + case catch gen:call(Name, '$gen_pcall', {Priority, Request}, Timeout) of + {ok,Res} -> + Res; + {'EXIT',Reason} -> + exit({Reason, {?MODULE, pcall, [Name, Priority, Request, Timeout]}}) + end. + %% ----------------------------------------------------------------- %% Make a cast to a generic server. %% ----------------------------------------------------------------- @@ -207,6 +223,22 @@ do_cast(Dest, Request) -> cast_msg(Request) -> {'$gen_cast',Request}. +pcast({global,Name}, Priority, Request) -> + catch global:send(Name, cast_msg(Priority, Request)), + ok; +pcast({Name,Node}=Dest, Priority, Request) when is_atom(Name), is_atom(Node) -> + do_cast(Dest, Priority, Request); +pcast(Dest, Priority, Request) when is_atom(Dest) -> + do_cast(Dest, Priority, Request); +pcast(Dest, Priority, Request) when is_pid(Dest) -> + do_cast(Dest, Priority, Request). + +do_cast(Dest, Priority, Request) -> + do_send(Dest, cast_msg(Priority, Request)), + ok. + +cast_msg(Priority, Request) -> {'$gen_pcast', {Priority, Request}}. + %% ----------------------------------------------------------------- %% Send a reply to the client. %% ----------------------------------------------------------------- @@ -326,7 +358,7 @@ init_it(Starter, Parent, Name, Mod, Args, Options) -> loop(Parent, Name, State, Mod, Time, Queue, Debug) -> receive Input -> loop(Parent, Name, State, Mod, - Time, priority_queue:in(Input, Queue), Debug) + Time, in(Input, Queue), Debug) after 0 -> case priority_queue:out(Queue) of {{value, Msg}, Queue1} -> @@ -336,14 +368,21 @@ loop(Parent, Name, State, Mod, Time, Queue, Debug) -> receive Input -> loop(Parent, Name, State, Mod, - Time, priority_queue:in(Input, Queue1), Debug) + Time, in(Input, Queue1), Debug) after Time -> process_msg(Parent, Name, State, Mod, Time, Queue1, Debug, timeout) end end end. - + +in({'$gen_pcast', {Priority, Msg}}, Queue) -> + priority_queue:in({'$gen_cast', Msg}, Priority, Queue); +in({'$gen_pcall', From, {Priority, Msg}}, Queue) -> + priority_queue:in({'$gen_call', From, Msg}, Priority, Queue); +in(Input, Queue) -> + priority_queue:in(Input, Queue). + process_msg(Parent, Name, State, Mod, Time, Queue, Debug, Msg) -> case Msg of {system, From, Req} -> diff --git a/src/priority_queue.erl b/src/priority_queue.erl index f660c0397d..484b526227 100644 --- a/src/priority_queue.erl +++ b/src/priority_queue.erl @@ -88,7 +88,8 @@ in(Item, Other) -> in(Item, infinity, Other). in(Item, Priority, {queue, In, Out}) -> - in(Item, Priority, {pqueue, 0, to_tree(In, Out)}); + {Counter, Tree} = to_tree(In, Out), + in(Item, Priority, {pqueue, Counter, Tree}); in(Item, Priority, {pqueue, Counter, Tree}) -> {pqueue, Counter + 1, gb_trees:insert({Priority, Counter}, Item, Tree)}. |
