diff options
| author | Matthew Sackman <matthew@lshift.net> | 2009-08-03 17:25:01 +0100 |
|---|---|---|
| committer | Matthew Sackman <matthew@lshift.net> | 2009-08-03 17:25:01 +0100 |
| commit | 091b70039aee2701a42b7e19ce1e48889638bb79 (patch) | |
| tree | 3fa5bae36bcbcb8a206cc8d0702c7a9e6f7822e2 | |
| parent | 7723b5d4340fb6a9978ec7b306bc0d19a58a0ae5 (diff) | |
| download | rabbitmq-server-git-091b70039aee2701a42b7e19ce1e48889638bb79.tar.gz | |
Matthias wanted to be able to cope with the possibility that we get woken up without having a msg to receive. We have no idea if this is possible. Nevertheless, in the previous code, it would block waiting for a msg (mirroring OTP behaviour). Now it'll work, but we have to avoid a potential crash elsewher.
| -rw-r--r-- | src/gen_server2.erl | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/gen_server2.erl b/src/gen_server2.erl index fc528b4df7..529ed0295e 100644 --- a/src/gen_server2.erl +++ b/src/gen_server2.erl @@ -450,15 +450,11 @@ loop(Parent, Name, State, Mod, hibernate, undefined, Queue, Debug) -> [Parent, Name, State, Mod, undefined, Queue, Debug]); loop(Parent, Name, State, Mod, Time, TimeoutState, Queue, Debug) -> process_next_msg(Parent, Name, State, Mod, Time, TimeoutState, - drain(Queue, false), Debug). + drain(Queue), Debug). -drain(Queue, true) -> +drain(Queue) -> receive - Input -> drain(in(Input, Queue), false) - end; -drain(Queue, false) -> - receive - Input -> drain(in(Input, Queue), false) + Input -> drain(in(Input, Queue)) after 0 -> Queue end. @@ -473,6 +469,16 @@ process_next_msg(Parent, Name, State, Mod, Time, TimeoutState, Queue, Debug) -> {hibernate, {backoff, Current, _Min, _Desired, _Pre, _Post}} -> {Current, true}; + {hibernate, _} -> + %% wake_hib/7 will set Time to hibernate. If + %% we were woken and didn't receive a msg + %% then we will get here and need a sensible + %% value for Time1, otherwise we crash. + %% On the grounds that it's better to get + %% control back to the user module sooner + %% rather than later, 0 is more sensible + %% than infinity here. + {0, false}; _ -> {Time, false} end, receive @@ -495,11 +501,11 @@ process_next_msg(Parent, Name, State, Mod, Time, TimeoutState, Queue, Debug) -> wake_hib(Parent, Name, State, Mod, TimeoutState, Queue, Debug) -> process_next_msg(Parent, Name, State, Mod, hibernate, TimeoutState, - drain(Queue, true), Debug). + drain(Queue), Debug). wake_hib(Parent, Name, State, Mod, SleptAt, TimeoutState, Queue, Debug) -> backoff_post_hibernate(Parent, Name, State, Mod, SleptAt, now(), - TimeoutState, drain(Queue, true), Debug). + TimeoutState, drain(Queue), Debug). backoff_pre_hibernate(Parent, Name, State, Mod, TimeoutState = {backoff, _Current, _Minimum, _Desired, Pre, _Post}, |
