Skip to content

Commit

Permalink
Merge pull request #36 from lpgauth/feature/make-increment-configurable
Browse files Browse the repository at this point in the history
Make backlog increment configurable
  • Loading branch information
lpgauth committed Dec 26, 2016
2 parents f099753 + 36c621c commit 500cdb9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/shackle_backlog.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,29 @@
%% internal
-export([
check/2,
check/3,
decrement/1,
delete/1,
init/0,
new/1
]).

-define(DEFAULT_INCREMENT, 1).

%% internal
-spec check(server_name(), backlog_size()) ->
boolean().

check(_ServerName, infinity) ->
true;
check(ServerName, BacklogSize) ->
case increment(ServerName, BacklogSize) of
check(ServerName, BacklogSize, ?DEFAULT_INCREMENT).

-spec check(server_name(), backlog_size(), pos_integer()) ->
boolean().

check(_ServerName, infinity, _Increment) ->
true;
check(ServerName, BacklogSize, Increment) ->
case increment(ServerName, BacklogSize, Increment) of
[BacklogSize, BacklogSize] ->
false;
[_, Value] when Value =< BacklogSize ->
Expand Down Expand Up @@ -61,6 +70,6 @@ new(ServerName) ->
ok.

%% private
increment(ServerName, BacklogSize) ->
UpdateOps = [{2, 0}, {2, 1, BacklogSize, BacklogSize}],
increment(ServerName, BacklogSize, Increment) ->
UpdateOps = [{2, 0}, {2, Increment, BacklogSize, BacklogSize}],
ets:update_counter(?ETS_TABLE_BACKLOG, ServerName, UpdateOps).

0 comments on commit 500cdb9

Please sign in to comment.