Created
September 5, 2012 21:27
-
-
Save thedarkone/3645105 to your computer and use it in GitHub Desktop.
Ruby volatile APIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using accessors: | |
attr_volatile :table, :size_control | |
def check_for_resize | |
while (current_table = table) && MAX_CAP > (table_size = current_table.size) && RESIZING != (size_ctrl = size_control) && size_ctrl < @counter.sum | |
try_in_resize_lock(current_table, size_ctrl) do | |
self.table = rebuild(current_table) | |
(table_size << 1) - (table_size >> 1) # 75% load factor | |
end | |
end | |
end | |
# using i-vars: | |
volatile :@table, :@size_control | |
def check_for_resize | |
while (table = @table) && MAX_CAP > (table_size = table.size) && RESIZING != (size_control = @size_control) && size_control < @counter.sum | |
try_in_resize_lock(table, size_control) do | |
@table = rebuild(table) | |
(table_size << 1) - (table_size >> 1) # 75% load factor | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment