fastthread 0.5.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_all.rb ADDED
@@ -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,31 @@
1
+ require 'test/unit'
2
+ $:.unshift File.expand_path( File.join( File.dirname( __FILE__ ), "../ext/fastthread" ) )
3
+ require 'fastthread'
4
+
5
+ class TestCondVar < Test::Unit::TestCase
6
+ def test_signal
7
+ s = ""
8
+ m = Mutex.new
9
+ cv = ConditionVariable.new
10
+ ready = false
11
+
12
+ t = Thread.new do
13
+ nil until m.synchronize { ready }
14
+ m.synchronize { s << "b" }
15
+ cv.signal
16
+ end
17
+
18
+ m.synchronize do
19
+ s << "a"
20
+ ready = true
21
+ cv.wait m
22
+ assert m.locked?
23
+ s << "c"
24
+ end
25
+
26
+ t.join
27
+
28
+ assert_equal "abc", s
29
+ end
30
+ end
31
+
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+ $:.unshift File.expand_path( File.join( File.dirname( __FILE__ ), "../ext/fastthread" ) )
3
+ require 'fastthread'
4
+
5
+ class TestMutex < Test::Unit::TestCase
6
+ def self.mutex_test( name, &body )
7
+ define_method( "test_#{ name }" ) do
8
+ body.call( self, Mutex.new, "" )
9
+ end
10
+ # at one time we also tested Mutex_m here, but it's no longer
11
+ # part of fastthread
12
+ end
13
+
14
+ mutex_test( :locked_p ) do |test, m, prefix|
15
+ test.instance_eval do
16
+ assert_equal false, m.send( "#{ prefix }locked?" )
17
+ m.send "#{ prefix }lock"
18
+ assert_equal true, m.send( "#{ prefix }locked?" )
19
+ m.send "#{ prefix }unlock"
20
+ assert_equal false, m.send( "#{ prefix }locked?" )
21
+ end
22
+ end
23
+
24
+ mutex_test( :synchronize ) do |test, m, prefix|
25
+ test.instance_eval do
26
+ assert !m.send( "#{ prefix }locked?" )
27
+ m.send "#{ prefix }synchronize" do
28
+ assert m.send( "#{ prefix }locked?" )
29
+ end
30
+ assert !m.send( "#{ prefix }locked?" )
31
+ end
32
+ end
33
+
34
+ mutex_test( :synchronize_exception ) do |test, m, prefix|
35
+ test.instance_eval do
36
+ assert !m.send( "#{ prefix }locked?" )
37
+ assert_raise ArgumentError do
38
+ m.send "#{ prefix }synchronize" do
39
+ assert m.send( "#{ prefix }locked?" )
40
+ raise ArgumentError
41
+ end
42
+ end
43
+ assert !m.send( "#{ prefix }locked?" )
44
+ end
45
+ end
46
+
47
+ mutex_test( :mutual_exclusion ) do |test, m, prefix|
48
+ test.instance_eval do
49
+ s = ""
50
+
51
+ ("a".."c").map do |c|
52
+ Thread.new do
53
+ Thread.pass
54
+ 5.times do
55
+ m.send "#{ prefix }synchronize" do
56
+ s << c
57
+ Thread.pass
58
+ s << c
59
+ end
60
+ end
61
+ end
62
+ end.each do |thread|
63
+ thread.join
64
+ end
65
+
66
+ assert_equal 30, s.length
67
+ assert s.match( /^(aa|bb|cc)+$/ )
68
+ end
69
+ end
70
+ end
71
+
@@ -0,0 +1,49 @@
1
+ require 'test/unit'
2
+ $:.unshift File.expand_path( File.join( File.dirname( __FILE__ ), "../ext/fastthread" ) )
3
+ require 'fastthread'
4
+
5
+ class TestQueue < Test::Unit::TestCase
6
+ def check_sequence( q )
7
+ range = "a".."f"
8
+
9
+ s = ""
10
+ e = nil
11
+
12
+ t = Thread.new do
13
+ begin
14
+ for c in range
15
+ q.push c
16
+ s << c
17
+ Thread.pass
18
+ end
19
+ rescue Exception => e
20
+ end
21
+ end
22
+
23
+ for c in range
24
+ unless t.alive?
25
+ raise e if e
26
+ assert_equal range.to_a.join, s, "expected all values pushed"
27
+ end
28
+ x = q.shift
29
+ assert_equal c, x, "sequence error: expected #{ c } but got #{ x }"
30
+ end
31
+ end
32
+
33
+ def test_queue
34
+ check_sequence( Queue.new )
35
+ end
36
+
37
+ def test_sized_queue_full
38
+ check_sequence( SizedQueue.new( 6 ) )
39
+ end
40
+
41
+ def test_sized_queue_half
42
+ check_sequence( SizedQueue.new( 3 ) )
43
+ end
44
+
45
+ def test_sized_queue_one
46
+ check_sequence( SizedQueue.new( 1 ) )
47
+ end
48
+ end
49
+
data/tools/rakehelp.rb ADDED
@@ -0,0 +1,117 @@
1
+ def make(makedir)
2
+ Dir.chdir(makedir) do
3
+ sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
4
+ end
5
+ end
6
+
7
+
8
+ def extconf(dir)
9
+ Dir.chdir(dir) do ruby "extconf.rb" end
10
+ end
11
+
12
+
13
+ def setup_tests
14
+ Rake::TestTask.new do |t|
15
+ t.libs << "test"
16
+ t.test_files = FileList['test/test*.rb']
17
+ t.verbose = true
18
+ end
19
+ end
20
+
21
+
22
+ def setup_clean otherfiles
23
+ files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles
24
+ CLEAN.include(files)
25
+ end
26
+
27
+
28
+ def setup_rdoc files
29
+ Rake::RDocTask.new do |rdoc|
30
+ rdoc.rdoc_dir = 'doc/rdoc'
31
+ rdoc.options << '--line-numbers'
32
+ rdoc.rdoc_files.add(files)
33
+ end
34
+ end
35
+
36
+
37
+ def setup_extension(dir, extension)
38
+ ext = "ext/#{dir}"
39
+ ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
40
+ ext_files = FileList[
41
+ "#{ext}/*.c",
42
+ "#{ext}/*.h",
43
+ "#{ext}/extconf.rb",
44
+ "#{ext}/Makefile",
45
+ "lib"
46
+ ]
47
+
48
+ task "lib" do
49
+ directory "lib"
50
+ end
51
+
52
+ desc "Builds just the #{extension} extension"
53
+ task extension.to_sym => ["#{ext}/Makefile", ext_so ]
54
+
55
+ file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
56
+ extconf "#{ext}"
57
+ end
58
+
59
+ file ext_so => ext_files do
60
+ make "#{ext}"
61
+ cp ext_so, "lib"
62
+ end
63
+ end
64
+
65
+
66
+ def base_gem_spec(pkg_name, pkg_version)
67
+ rm_rf "test/coverage"
68
+ pkg_version = pkg_version
69
+ pkg_name = pkg_name
70
+ pkg_file_name = "#{pkg_name}-#{pkg_version}"
71
+ Gem::Specification.new do |s|
72
+ s.name = pkg_name
73
+ s.version = pkg_version
74
+ s.platform = Gem::Platform::RUBY
75
+ s.has_rdoc = true
76
+ s.extra_rdoc_files = [ "README" ]
77
+
78
+ s.files = %w(COPYING LICENSE README Rakefile) +
79
+ Dir.glob("{bin,doc/rdoc,test}/**/*") +
80
+ Dir.glob("ext/**/*.{h,c,rb,rl}") +
81
+ Dir.glob("{examples,tools,lib}/**/*.rb")
82
+
83
+ s.require_path = "lib"
84
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
85
+ s.bindir = "bin"
86
+ end
87
+ end
88
+
89
+ def setup_gem(pkg_name, pkg_version)
90
+ spec = base_gem_spec(pkg_name, pkg_version)
91
+ yield spec if block_given?
92
+
93
+ Rake::GemPackageTask.new(spec) do |p|
94
+ p.gem_spec = spec
95
+ p.need_tar = true if RUBY_PLATFORM !~ /mswin/
96
+ end
97
+ end
98
+
99
+ def sub_project(project, *targets)
100
+ targets.each do |target|
101
+ Dir.chdir "projects/#{project}" do
102
+ sh %{rake --trace #{target.to_s} }
103
+ end
104
+ end
105
+ end
106
+
107
+ # Conditional require rcov/rcovtask if present
108
+ begin
109
+ require 'rcov/rcovtask'
110
+
111
+ Rcov::RcovTask.new do |t|
112
+ t.test_files = FileList['test/test*.rb']
113
+ t.rcov_opts << "-x /usr"
114
+ t.output_dir = "test/coverage"
115
+ end
116
+ rescue Object
117
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: fastthread
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.3.5
7
+ date: 2006-12-30 00:00:00 -05:00
8
+ summary: Optimized replacement for thread.rb primitives
9
+ require_paths:
10
+ - lib
11
+ email:
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - MenTaLguY <mental@rydia.net>
30
+ files:
31
+ - Rakefile
32
+ - setup.rb
33
+ - test/test_all.rb
34
+ - test/test_condvar.rb
35
+ - test/test_mutex.rb
36
+ - test/test_queue.rb
37
+ - ext/fastthread/fastthread.c
38
+ - ext/fastthread/extconf.rb
39
+ - tools/rakehelp.rb
40
+ test_files:
41
+ - test/test_all.rb
42
+ rdoc_options: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ executables: []
47
+
48
+ extensions:
49
+ - ext/fastthread/extconf.rb
50
+ requirements: []
51
+
52
+ dependencies: []
53
+