Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decrease-max-fix #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TylerPachal
Copy link

@TylerPachal TylerPachal commented Apr 27, 2021

Fixes the behaviour of the acquire/2 function when you provide a max which is less than the current count.

See the issue for more details: #6

"""
@spec acquire(term, integer) :: boolean
def acquire(name, max) do
case ETS.update_counter(@table, name, [{2, 0}, {2, 1, max, max}], {name, 0}) do
[^max, _] -> false
_ -> true
[old_val, new_val] -> old_val < new_val
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: This is the main fix.

As long as the old_val is less than the new_val then we know that we have acquired a lock successfully, whether you are incrementing the max, decrementing the max, or leaving it the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants