Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/thread_safe/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ module ThreadSafe
end

class Cache < ConcurrentCacheBackend
KEY_ERROR = defined?(KeyError) ? KeyError : IndexError # there is no KeyError in 1.8 mode

def initialize(options = nil, &block)
if options.kind_of?(::Hash)
validate_options_hash!(options)
Expand Down Expand Up @@ -138,7 +136,7 @@ def marshal_load(hash)

private
def raise_fetch_no_key
raise KEY_ERROR, 'key not found'
raise KeyError, 'key not found'
end

def initialize_copy(other)
Expand Down
9 changes: 0 additions & 9 deletions lib/thread_safe/mri_cache_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ class MriCacheBackend < NonConcurrentCacheBackend
# We can get away with a single global write lock (instead of a per-instance
# one) because of the GVL/green threads.
#
# The previous implementation used `Thread.critical` on 1.8 MRI to implement
# the 4 composed atomic operations (`put_if_absent`, `replace_pair`,
# `replace_if_exists`, `delete_pair`) this however doesn't work for
# `compute_if_absent` because on 1.8 the Mutex class is itself implemented
# via `Thread.critical` and a call to `Mutex#lock` does not restore the
# previous `Thread.critical` value (thus any synchronisation clears the
# `Thread.critical` flag and we loose control). This poses a problem as the
# provided block might use synchronisation on its own.
#
# NOTE: a neat idea of writing a c-ext to manually perform atomic
# put_if_absent, while relying on Ruby not releasing a GVL while calling a
# c-ext will not work because of the potentially Ruby implemented `#hash`
Expand Down
17 changes: 0 additions & 17 deletions lib/thread_safe/synchronized_delegator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,4 @@ def method_missing(method, *args, &block)
end
end

# Work-around for 1.8 std-lib not passing block around to delegate.
# @private
def method_missing(method, *args, &block)
monitor = @monitor
begin
monitor.enter
target = self.__getobj__
if target.respond_to?(method)
target.__send__(method, *args, &block)
else
super(method, *args, &block)
end
ensure
monitor.exit
end
end if RUBY_VERSION[0, 3] == '1.8'

end unless defined?(SynchronizedDelegator)
1 change: 0 additions & 1 deletion lib/thread_safe/util/atomic_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module Util
require 'atomic'
defined?(Atomic::InternalReference) ? Atomic::InternalReference : Atomic
rescue LoadError, NameError
require 'thread' # get Mutex on 1.8
class FullLockingAtomicReference
def initialize(value = nil)
@___mutex = Mutex.new
Expand Down
2 changes: 1 addition & 1 deletion spec/thread_safe/cache_loops_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,5 +503,5 @@ def expect_count_up(result, cache, options, keys)
expect(sum(cache.values)).to eq sum(result)
expect(options[:key_count]).to eq cache.size
end
end unless RUBY_VERSION =~ /1\.8/ || RUBY_ENGINE == 'rbx' || ENV['TRAVIS']
end unless RUBY_ENGINE == 'rbx' || ENV['TRAVIS']
end
5 changes: 2 additions & 3 deletions spec/thread_safe/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ def key # assert_collision_resistance expects to be able to call .key to get the
@cache[:a] = 1
expect(:a).to eq @cache.key(1)
expect(nil).to eq @cache.key(0)
expect(:a).to eq @cache.index(1) if RUBY_VERSION =~ /1\.8/
end
end

Expand Down Expand Up @@ -492,7 +491,7 @@ def key # assert_collision_resistance expects to be able to call .key to get the
expect(1).to eq @cache.fetch(:a) { flunk }
end

expect { @cache.fetch(:b) }.to raise_error(ThreadSafe::Cache::KEY_ERROR)
expect { @cache.fetch(:b) }.to raise_error(KeyError)

expect_no_size_change do
expect(1).to eq @cache.fetch(:b, :c) {1} # assert block supersedes default value argument
Expand Down Expand Up @@ -555,7 +554,7 @@ def key # assert_collision_resistance expects to be able to call .key to get the
end

expect { @cache.fetch_or_store(:b) }.
to raise_error(ThreadSafe::Cache::KEY_ERROR)
to raise_error(KeyError)

expect_size_change(1) do
expect(1).to eq @cache.fetch_or_store(:b, :c) { 1 } # assert block supersedes default value argument
Expand Down