Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

Commit fa5a8af

Browse files
committed
Merge pull request #20 from dzjuck/remove_1_8
Remove code related to Ruby 1.8
2 parents c096fdf + 4ad7737 commit fa5a8af

File tree

6 files changed

+4
-34
lines changed

6 files changed

+4
-34
lines changed

lib/thread_safe/cache.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ module ThreadSafe
2121
end
2222

2323
class Cache < ConcurrentCacheBackend
24-
KEY_ERROR = defined?(KeyError) ? KeyError : IndexError # there is no KeyError in 1.8 mode
25-
2624
def initialize(options = nil, &block)
2725
if options.kind_of?(::Hash)
2826
validate_options_hash!(options)
@@ -138,7 +136,7 @@ def marshal_load(hash)
138136

139137
private
140138
def raise_fetch_no_key
141-
raise KEY_ERROR, 'key not found'
139+
raise KeyError, 'key not found'
142140
end
143141

144142
def initialize_copy(other)

lib/thread_safe/mri_cache_backend.rb

-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ class MriCacheBackend < NonConcurrentCacheBackend
33
# We can get away with a single global write lock (instead of a per-instance
44
# one) because of the GVL/green threads.
55
#
6-
# The previous implementation used `Thread.critical` on 1.8 MRI to implement
7-
# the 4 composed atomic operations (`put_if_absent`, `replace_pair`,
8-
# `replace_if_exists`, `delete_pair`) this however doesn't work for
9-
# `compute_if_absent` because on 1.8 the Mutex class is itself implemented
10-
# via `Thread.critical` and a call to `Mutex#lock` does not restore the
11-
# previous `Thread.critical` value (thus any synchronisation clears the
12-
# `Thread.critical` flag and we loose control). This poses a problem as the
13-
# provided block might use synchronisation on its own.
14-
#
156
# NOTE: a neat idea of writing a c-ext to manually perform atomic
167
# put_if_absent, while relying on Ruby not releasing a GVL while calling a
178
# c-ext will not work because of the potentially Ruby implemented `#hash`

lib/thread_safe/synchronized_delegator.rb

-17
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,4 @@ def method_missing(method, *args, &block)
4040
end
4141
end
4242

43-
# Work-around for 1.8 std-lib not passing block around to delegate.
44-
# @private
45-
def method_missing(method, *args, &block)
46-
monitor = @monitor
47-
begin
48-
monitor.enter
49-
target = self.__getobj__
50-
if target.respond_to?(method)
51-
target.__send__(method, *args, &block)
52-
else
53-
super(method, *args, &block)
54-
end
55-
ensure
56-
monitor.exit
57-
end
58-
end if RUBY_VERSION[0, 3] == '1.8'
59-
6043
end unless defined?(SynchronizedDelegator)

lib/thread_safe/util/atomic_reference.rb

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module Util
99
require 'atomic'
1010
defined?(Atomic::InternalReference) ? Atomic::InternalReference : Atomic
1111
rescue LoadError, NameError
12-
require 'thread' # get Mutex on 1.8
1312
class FullLockingAtomicReference
1413
def initialize(value = nil)
1514
@___mutex = Mutex.new

spec/thread_safe/cache_loops_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,5 +503,5 @@ def expect_count_up(result, cache, options, keys)
503503
expect(sum(cache.values)).to eq sum(result)
504504
expect(options[:key_count]).to eq cache.size
505505
end
506-
end unless RUBY_VERSION =~ /1\.8/ || RUBY_ENGINE == 'rbx' || ENV['TRAVIS']
506+
end unless RUBY_ENGINE == 'rbx' || ENV['TRAVIS']
507507
end

spec/thread_safe/cache_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ def key # assert_collision_resistance expects to be able to call .key to get the
397397
@cache[:a] = 1
398398
expect(:a).to eq @cache.key(1)
399399
expect(nil).to eq @cache.key(0)
400-
expect(:a).to eq @cache.index(1) if RUBY_VERSION =~ /1\.8/
401400
end
402401
end
403402

@@ -492,7 +491,7 @@ def key # assert_collision_resistance expects to be able to call .key to get the
492491
expect(1).to eq @cache.fetch(:a) { fail }
493492
end
494493

495-
expect { @cache.fetch(:b) }.to raise_error(ThreadSafe::Cache::KEY_ERROR)
494+
expect { @cache.fetch(:b) }.to raise_error(KeyError)
496495

497496
expect_no_size_change do
498497
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
555554
end
556555

557556
expect { @cache.fetch_or_store(:b) }.
558-
to raise_error(ThreadSafe::Cache::KEY_ERROR)
557+
to raise_error(KeyError)
559558

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

0 commit comments

Comments
 (0)