diff --git a/lib/thread_safe/cache.rb b/lib/thread_safe/cache.rb index 2539941..109cb98 100644 --- a/lib/thread_safe/cache.rb +++ b/lib/thread_safe/cache.rb @@ -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) @@ -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) diff --git a/lib/thread_safe/mri_cache_backend.rb b/lib/thread_safe/mri_cache_backend.rb index 975bc46..13e57b3 100644 --- a/lib/thread_safe/mri_cache_backend.rb +++ b/lib/thread_safe/mri_cache_backend.rb @@ -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` diff --git a/lib/thread_safe/synchronized_delegator.rb b/lib/thread_safe/synchronized_delegator.rb index 26c768c..2fc351d 100644 --- a/lib/thread_safe/synchronized_delegator.rb +++ b/lib/thread_safe/synchronized_delegator.rb @@ -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) diff --git a/lib/thread_safe/util/atomic_reference.rb b/lib/thread_safe/util/atomic_reference.rb index 4d01e9f..04800f1 100644 --- a/lib/thread_safe/util/atomic_reference.rb +++ b/lib/thread_safe/util/atomic_reference.rb @@ -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 diff --git a/spec/thread_safe/cache_loops_spec.rb b/spec/thread_safe/cache_loops_spec.rb index 7de8f80..f29dc54 100644 --- a/spec/thread_safe/cache_loops_spec.rb +++ b/spec/thread_safe/cache_loops_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/thread_safe/cache_spec.rb b/spec/thread_safe/cache_spec.rb index 8a68801..be90353 100644 --- a/spec/thread_safe/cache_spec.rb +++ b/spec/thread_safe/cache_spec.rb @@ -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 @@ -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 @@ -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