Permalink
Browse files

Change the code to be more in style with what we want.

  • Loading branch information...
1 parent bf72198 commit fa557e5d44312415aed1b9195f27eadbc675664c @jlouis committed Dec 23, 2012
Showing with 8 additions and 6 deletions.
  1. +5 −3 src/sv_codel.erl
  2. +1 −1 src/sv_queue.erl
  3. +2 −2 src/sv_queue_ets.erl
View
@@ -17,14 +17,16 @@
%% Scrutiny
-export([qstate/1]).
+-define(Q, queue).
+
-type task() :: term().
%% Internal state
-record(state, {
%% The underlying queue to use. For now, since we are mainly in a test phase, we just use a standard
%% functional queue. But later the plan is to use a module here and then call the right kind of queue
%% functions for that module.
- queue = queue:new(),
+ queue = ?Q:new(),
%% The `dropping' field tracks if the CoDel system is in a dropping state or not.
dropping = false,
@@ -87,7 +89,7 @@ init(Target, Interval) -> #state{ target = Target, interval = Interval }.
%% @end
-spec enqueue(task(), term(), #state{}) -> #state{}.
enqueue(Pkt, TS, #state { queue = Q } = State) ->
- State#state { queue = queue:in({Pkt, TS}, Q) }.
+ State#state { queue = ?Q:in({Pkt, TS}, Q) }.
%% @doc Dequeue a packet from the CoDel system
%% Given a point in time, `Now' and a CoDel `State', extract the next task from it.
@@ -114,7 +116,7 @@ control_law(T, I, C) ->
%% This is a helper function. It dequeues from the underlying queue and then analyzes the Sojourn
%% time together with the next function, dodequeue_.
dodequeue(Now, #state { queue = Q } = State) ->
- case queue:out(Q) of
+ case ?Q:out(Q) of
{empty, NQ} ->
{nodrop, empty, State#state { first_above_time = 0, queue = NQ }};
{{value, {Pkt, InT}}, NQ} ->
View
@@ -190,7 +190,7 @@ process_queue(0, Q, TS, Started) ->
{Started, Q, TS};
process_queue(K, Q, TS, Started) ->
case ?QUEUE:out(Q) of
- {{value, {_Timestamp, {Pid, _} = From}}, Q2} ->
+ {{value, {Pid, _}= From}, Q2} ->
Ref = erlang:monitor(process, Pid),
gen_server:reply(From, {go, Ref}),
process_queue(K-1, Q2, gb_sets:add_element(Ref, TS), Started+1);
View
@@ -33,9 +33,9 @@ out(QName) ->
case ets:first(QName) of
'$end_of_table' -> {empty, QName};
Key ->
- [Obj] = ets:lookup(QName, Key),
+ [{_TS, V} = Obj] = ets:lookup(QName, Key),
true = ets:delete_object(QName, Obj),
- {{value, Obj}, QName}
+ {{value, V}, QName}
end.
len(QName) ->

0 comments on commit fa557e5

Please sign in to comment.