thread_safe 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ require 'thread'
2
+
3
+ module ThreadSafe
4
+ module Test
5
+ class Latch
6
+ def initialize(count = 1)
7
+ @count = count
8
+ @mutex = Mutex.new
9
+ @cond = ConditionVariable.new
10
+ end
11
+
12
+ def release
13
+ @mutex.synchronize do
14
+ @count -= 1 if @count > 0
15
+ @cond.broadcast if @count.zero?
16
+ end
17
+ end
18
+
19
+ def await
20
+ @mutex.synchronize do
21
+ @cond.wait @mutex if @count > 0
22
+ end
23
+ end
24
+ end
25
+
26
+ class Barrier < Latch
27
+ def await
28
+ @mutex.synchronize do
29
+ if @count.zero? # fall through
30
+ elsif @count > 0
31
+ @count -= 1
32
+ @count.zero? ? @cond.broadcast : @cond.wait(@mutex)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ class HashCollisionKey
39
+ attr_reader :hash, :key
40
+ def initialize(key, hash = key.hash % 3)
41
+ @key = key
42
+ @hash = hash
43
+ end
44
+
45
+ def eql?(other)
46
+ other.kind_of?(self.class) && @key.eql?(other.key)
47
+ end
48
+
49
+ def even?
50
+ @key.even?
51
+ end
52
+
53
+ def <=>(other)
54
+ @key <=> other.key
55
+ end
56
+ end
57
+
58
+ # having 4 separate HCK classes helps for a more thorough CHMV8 testing
59
+ class HashCollisionKey2 < HashCollisionKey; end
60
+ class HashCollisionKeyNoCompare < HashCollisionKey
61
+ def <=>(other)
62
+ 0
63
+ end
64
+ end
65
+ class HashCollisionKey4 < HashCollisionKeyNoCompare; end
66
+
67
+ HASH_COLLISION_CLASSES = [HashCollisionKey, HashCollisionKey2, HashCollisionKeyNoCompare, HashCollisionKey4]
68
+
69
+ def self.HashCollisionKey(key)
70
+ HASH_COLLISION_CLASSES[rand(4)].new(key)
71
+ end
72
+ end
73
+ end
data/thread_safe.gemspec CHANGED
@@ -2,16 +2,19 @@
2
2
  require File.expand_path('../lib/thread_safe/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Charles Oliver Nutter"]
6
- gem.email = ["headius@headius.com"]
5
+ gem.authors = ["Charles Oliver Nutter", "thedarkone"]
6
+ gem.email = ["headius@headius.com", "thedarkone2@gmail.com"]
7
7
  gem.description = %q{Thread-safe collections and utilities for Ruby}
8
8
  gem.summary = %q{A collection of data structures and utilities to make thread-safe programming in Ruby easier}
9
9
  gem.homepage = "https://github.com/headius/thread_safe"
10
10
 
11
- gem.files = `git ls-files`.split($\)
11
+ gem.files = `git ls-files`.split($\) | Dir['{lib,examples,test}/**/*.jar']
12
+ gem.platform = 'java' if defined?(JRUBY_VERSION)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
15
  gem.name = "thread_safe"
15
16
  gem.require_paths = ["lib"]
16
17
  gem.version = Threadsafe::VERSION
18
+
19
+ gem.add_dependency 'atomic'
17
20
  end
metadata CHANGED
@@ -1,21 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thread_safe
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease:
5
- version: 0.0.3
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
6
11
  platform: ruby
7
12
  authors:
8
- - Charles Oliver Nutter
13
+ - Charles Oliver Nutter
14
+ - thedarkone
9
15
  autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2012-04-27 00:00:00 Z
14
- dependencies: []
15
-
19
+ date: 2012-12-13 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: atomic
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
16
36
  description: Thread-safe collections and utilities for Ruby
17
37
  email:
18
- - headius@headius.com
38
+ - headius@headius.com
39
+ - thedarkone2@gmail.com
19
40
  executables: []
20
41
 
21
42
  extensions: []
@@ -23,16 +44,42 @@ extensions: []
23
44
  extra_rdoc_files: []
24
45
 
25
46
  files:
26
- - .gitignore
27
- - Gemfile
28
- - LICENSE
29
- - README.md
30
- - Rakefile
31
- - lib/thread_safe.rb
32
- - lib/thread_safe/version.rb
33
- - test/test_array.rb
34
- - test/test_hash.rb
35
- - thread_safe.gemspec
47
+ - .gitignore
48
+ - Gemfile
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - examples/bench_cache.rb
53
+ - ext/org/jruby/ext/thread_safe/JRubyCacheBackendLibrary.java
54
+ - ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java
55
+ - ext/org/jruby/ext/thread_safe/jsr166e/LongAdder.java
56
+ - ext/org/jruby/ext/thread_safe/jsr166e/Striped64.java
57
+ - ext/org/jruby/ext/thread_safe/jsr166y/ThreadLocalRandom.java
58
+ - ext/thread_safe/JrubyCacheBackendService.java
59
+ - lib/thread_safe.rb
60
+ - lib/thread_safe/atomic_reference_cache_backend.rb
61
+ - lib/thread_safe/cache.rb
62
+ - lib/thread_safe/mri_cache_backend.rb
63
+ - lib/thread_safe/non_concurrent_cache_backend.rb
64
+ - lib/thread_safe/synchronized_cache_backend.rb
65
+ - lib/thread_safe/util.rb
66
+ - lib/thread_safe/util/adder.rb
67
+ - lib/thread_safe/util/atomic_reference.rb
68
+ - lib/thread_safe/util/cheap_lockable.rb
69
+ - lib/thread_safe/util/power_of_two_tuple.rb
70
+ - lib/thread_safe/util/striped64.rb
71
+ - lib/thread_safe/util/volatile.rb
72
+ - lib/thread_safe/util/volatile_tuple.rb
73
+ - lib/thread_safe/util/xor_shift_random.rb
74
+ - lib/thread_safe/version.rb
75
+ - test/test_array.rb
76
+ - test/test_cache.rb
77
+ - test/test_cache_loops.rb
78
+ - test/test_hash.rb
79
+ - test/test_helper.rb
80
+ - thread_safe.gemspec
81
+ - lib/thread_safe/jruby_cache_backend.jar
82
+ has_rdoc: true
36
83
  homepage: https://github.com/headius/thread_safe
37
84
  licenses: []
38
85
 
@@ -40,26 +87,35 @@ post_install_message:
40
87
  rdoc_options: []
41
88
 
42
89
  require_paths:
43
- - lib
90
+ - lib
44
91
  required_ruby_version: !ruby/object:Gem::Requirement
45
92
  none: false
46
93
  requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: "0"
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
50
100
  required_rubygems_version: !ruby/object:Gem::Requirement
51
101
  none: false
52
102
  requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
56
109
  requirements: []
57
110
 
58
111
  rubyforge_project:
59
- rubygems_version: 1.8.23
112
+ rubygems_version: 1.5.2
60
113
  signing_key:
61
114
  specification_version: 3
62
115
  summary: A collection of data structures and utilities to make thread-safe programming in Ruby easier
63
116
  test_files:
64
- - test/test_array.rb
65
- - test/test_hash.rb
117
+ - test/test_array.rb
118
+ - test/test_cache.rb
119
+ - test/test_cache_loops.rb
120
+ - test/test_hash.rb
121
+ - test/test_helper.rb