blackwinter-fastthread 1.0.5

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,6 @@
1
+ require 'test/unit'
2
+ $:.unshift File.expand_path( File.dirname( __FILE__ ) )
3
+ require 'test_mutex'
4
+ require 'test_condvar'
5
+ require 'test_queue'
6
+
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+ require 'thread'
3
+ if RUBY_PLATFORM != "java"
4
+ $:.unshift File.expand_path( File.join( File.dirname( __FILE__ ), "../ext/fastthread" ) )
5
+ require 'fastthread'
6
+ end
7
+
8
+ class TestCondVar < Test::Unit::TestCase
9
+ def test_signal
10
+ s = ""
11
+ m = Mutex.new
12
+ cv = ConditionVariable.new
13
+ ready = false
14
+
15
+ t = Thread.new do
16
+ nil until ( Thread.pass ; m.synchronize { ready } )
17
+ m.synchronize { s << "b" }
18
+ cv.signal
19
+ end
20
+
21
+ m.synchronize do
22
+ s << "a"
23
+ ready = true
24
+ cv.wait m
25
+ assert m.locked?
26
+ s << "c"
27
+ end
28
+
29
+ t.join
30
+
31
+ assert_equal "abc", s
32
+ end
33
+ end
34
+
@@ -0,0 +1,74 @@
1
+ require 'test/unit'
2
+ require 'thread'
3
+ if RUBY_PLATFORM != "java"
4
+ $:.unshift File.expand_path( File.join( File.dirname( __FILE__ ), "../ext/fastthread" ) )
5
+ require 'fastthread'
6
+ end
7
+
8
+ class TestMutex < Test::Unit::TestCase
9
+ def self.mutex_test( name, &body )
10
+ define_method( "test_#{ name }" ) do
11
+ body.call( self, Mutex.new, "" )
12
+ end
13
+ # at one time we also tested Mutex_m here, but it's no longer
14
+ # part of fastthread
15
+ end
16
+
17
+ mutex_test( :locked_p ) do |test, m, prefix|
18
+ test.instance_eval do
19
+ assert_equal false, m.send( "#{ prefix }locked?" )
20
+ m.send "#{ prefix }lock"
21
+ assert_equal true, m.send( "#{ prefix }locked?" )
22
+ m.send "#{ prefix }unlock"
23
+ assert_equal false, m.send( "#{ prefix }locked?" )
24
+ end
25
+ end
26
+
27
+ mutex_test( :synchronize ) do |test, m, prefix|
28
+ test.instance_eval do
29
+ assert !m.send( "#{ prefix }locked?" )
30
+ m.send "#{ prefix }synchronize" do
31
+ assert m.send( "#{ prefix }locked?" )
32
+ end
33
+ assert !m.send( "#{ prefix }locked?" )
34
+ end
35
+ end
36
+
37
+ mutex_test( :synchronize_exception ) do |test, m, prefix|
38
+ test.instance_eval do
39
+ assert !m.send( "#{ prefix }locked?" )
40
+ assert_raise ArgumentError do
41
+ m.send "#{ prefix }synchronize" do
42
+ assert m.send( "#{ prefix }locked?" )
43
+ raise ArgumentError
44
+ end
45
+ end
46
+ assert !m.send( "#{ prefix }locked?" )
47
+ end
48
+ end
49
+
50
+ mutex_test( :mutual_exclusion ) do |test, m, prefix|
51
+ test.instance_eval do
52
+ s = ""
53
+
54
+ ("a".."c").map do |c|
55
+ Thread.new do
56
+ Thread.pass
57
+ 5.times do
58
+ m.send "#{ prefix }synchronize" do
59
+ s << c
60
+ Thread.pass
61
+ s << c
62
+ end
63
+ end
64
+ end
65
+ end.each do |thread|
66
+ thread.join
67
+ end
68
+
69
+ assert_equal 30, s.length
70
+ assert s.match( /^(aa|bb|cc)+$/ )
71
+ end
72
+ end
73
+ end
74
+
@@ -0,0 +1,79 @@
1
+ require 'test/unit'
2
+ require 'thread'
3
+ if RUBY_PLATFORM != "java"
4
+ $:.unshift File.expand_path( File.join( File.dirname( __FILE__ ), "../ext/fastthread" ) )
5
+ require 'fastthread'
6
+ end
7
+
8
+ class TestQueue < Test::Unit::TestCase
9
+ def check_sequence( q )
10
+ range = "a".."f"
11
+
12
+ s = ""
13
+ e = nil
14
+
15
+ t = Thread.new do
16
+ begin
17
+ for c in range
18
+ q.push c
19
+ s << c
20
+ Thread.pass
21
+ end
22
+ rescue Exception => e
23
+ end
24
+ end
25
+
26
+ for c in range
27
+ unless t.alive?
28
+ raise e if e
29
+ assert_equal range.to_a.join, s, "expected all values pushed"
30
+ end
31
+ x = q.shift
32
+ assert_equal c, x, "sequence error: expected #{ c } but got #{ x }"
33
+ end
34
+ end
35
+
36
+ def test_queue
37
+ check_sequence( Queue.new )
38
+ end
39
+
40
+ def test_sized_queue_full
41
+ check_sequence( SizedQueue.new( 6 ) )
42
+ end
43
+
44
+ def test_sized_queue_half
45
+ check_sequence( SizedQueue.new( 3 ) )
46
+ end
47
+
48
+ def test_sized_queue_one
49
+ check_sequence( SizedQueue.new( 1 ) )
50
+ end
51
+
52
+ def check_serialization( k, *args )
53
+ q1 = k.new *args
54
+ %w(a b c d e f).each { |c| q1.push c }
55
+ q2 = Marshal.load(Marshal.dump(q1))
56
+ assert( ( q1.size == q2.size ), "queues are same size" )
57
+ q1.size.times do
58
+ assert( ( q1.pop == q2.pop ), "same data" )
59
+ end
60
+ [ q1, q2 ]
61
+ end
62
+
63
+ def test_queue_serialization
64
+ check_serialization Queue
65
+ end
66
+
67
+ def test_sized_queue_serialization
68
+ (q1, q2) = check_serialization SizedQueue, 20
69
+ assert( ( q1.max == q2.max ), "maximum sizes equal" )
70
+ end
71
+
72
+ def test_sized_queue_size
73
+ q = SizedQueue.new 3
74
+ assert_equal 3, q.max, "queue has expected max (3)"
75
+ q.max = 5
76
+ assert_equal 5, q.max, "queue has expected max (5)"
77
+ end
78
+ end
79
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blackwinter-fastthread
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
+ platform: ruby
6
+ authors:
7
+ - MenTaLguY <mental@rydia.net>
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-27 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Optimized replacement for thread.rb primitives
17
+ email: mental@rydia.net
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/fastthread/extconf.rb
22
+ extra_rdoc_files:
23
+ - ext/fastthread/fastthread.c
24
+ - ext/fastthread/extconf.rb
25
+ - CHANGELOG
26
+ files:
27
+ - test/test_queue.rb
28
+ - test/test_mutex.rb
29
+ - test/test_condvar.rb
30
+ - test/test_all.rb
31
+ - setup.rb
32
+ - Manifest
33
+ - ext/fastthread/fastthread.c
34
+ - ext/fastthread/extconf.rb
35
+ - CHANGELOG
36
+ - fastthread.gemspec
37
+ - Rakefile
38
+ has_rdoc: true
39
+ homepage: ""
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --line-numbers
43
+ - --inline-source
44
+ - --title
45
+ - Fastthread
46
+ require_paths:
47
+ - ext
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "1.2"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project: mongrel
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: Optimized replacement for thread.rb primitives
67
+ test_files:
68
+ - test/test_all.rb