win32-semaphore 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.3.2 - 23-Mar-2012
2
+ * Refactored the Rakefile and cleaned up the gemspec.
3
+ * Removed one test that was originally designed for the C version.
4
+
1
5
  == 0.3.1 - 11-Aug-2009
2
6
  * Changed license to Artistic 2.0.
3
7
  * The Semaphore.open method is now slightly more robust.
@@ -36,4 +40,4 @@
36
40
  * Added more tests.
37
41
 
38
42
  == 0.1.0 - 14-May-2004
39
- * Initial release
43
+ * Initial release
data/README CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
  == Known Bugs
38
38
  None known. Any bugs should be reported on the project page at
39
- http://rubyforge.org/projects/win32utils.
39
+ http://www.github.com/djberg96/win32-semaphore
40
40
 
41
41
  == Future Plans
42
42
  Suggestions welcome.
@@ -45,7 +45,7 @@
45
45
  Artistic 2.0
46
46
 
47
47
  == Copyright
48
- (C) 2003-2009 Daniel J. Berger
48
+ (C) 2003-2012 Daniel J. Berger
49
49
  All Rights Reserved
50
50
 
51
51
  == Warranty
@@ -53,6 +53,6 @@
53
53
  implied warranties, including, without limitation, the implied
54
54
  warranties of merchantability and fitness for a particular purpose.
55
55
 
56
- == Author(s)
56
+ == Authors
57
57
  Daniel J. Berger
58
58
  Park Heesob
data/Rakefile CHANGED
@@ -1,24 +1,31 @@
1
1
  require 'rake'
2
+ require 'rake/clean'
2
3
  require 'rake/testtask'
3
- require 'rbconfig'
4
- include Config
5
4
 
6
- desc 'Install the win32-semaphore package (non-gem)'
7
- task :install do
8
- sitelibdir = CONFIG['sitelibdir']
9
- installdir = File.join(sitelibdir, 'win32')
10
- file = 'lib\win32\semaphore.rb'
5
+ CLEAN.include("**/*.gem")
11
6
 
12
- Dir.mkdir(installdir) unless File.exists?(installdir)
13
- FileUtils.cp(file, installdir, :verbose => true)
7
+ namespace :gem do
8
+ desc 'Create the win32-semaphore gem'
9
+ task :create => [:clean] do
10
+ spec = eval(IO.read('win32-semaphore.gemspec'))
11
+ Gem::Builder.new(spec).build
12
+ end
13
+
14
+ desc 'Install the win32-semaphore gem'
15
+ task :install => [:create] do
16
+ file = Dir["*.gem"].first
17
+ sh "gem install #{file}"
18
+ end
14
19
  end
15
20
 
16
21
  desc 'Run the example program'
17
22
  task :example do
18
- ruby '-Ilib examples/example_semaphore.rb'
23
+ ruby '-Ilib examples/example_semaphore.rb'
19
24
  end
20
25
 
21
26
  Rake::TestTask.new do |t|
22
- t.verbose = true
23
- t.warning = true
27
+ t.verbose = true
28
+ t.warning = true
24
29
  end
30
+
31
+ task :default => :test
@@ -5,17 +5,17 @@ module Win32
5
5
 
6
6
  # The Semaphore class encapsulates semaphore objects on Windows.
7
7
  class Semaphore < Ipc
8
-
8
+
9
9
  # This is the error raised if any of the Semaphore methods fail.
10
10
  class Error < StandardError; end
11
-
11
+
12
12
  extend Windows::Synchronize
13
13
  extend Windows::Error
14
14
  extend Windows::Handle
15
-
15
+
16
16
  # The version of the win32-semaphore library
17
- VERSION = '0.3.1'
18
-
17
+ VERSION = '0.3.2'
18
+
19
19
  # The initial count for the semaphore object. This value must be greater
20
20
  # than or equal to zero and less than or equal to +max_count+. The state
21
21
  # of a semaphore is signaled when its count is greater than zero and
@@ -25,16 +25,16 @@ module Win32
25
25
  # Semaphore#release method.
26
26
  #
27
27
  attr_reader :initial_count
28
-
28
+
29
29
  # The maximum count for the semaphore object. This value must be
30
- # greater than zero.
30
+ # greater than zero.
31
31
  #
32
32
  attr_reader :max_count
33
-
33
+
34
34
  # The name of the Semaphore object.
35
35
  #
36
36
  attr_reader :name
37
-
37
+
38
38
  # Creates and returns new Semaphore object. If +name+ is omitted, the
39
39
  # Semaphore object is created without a name, i.e. it's anonymous.
40
40
  #
@@ -54,12 +54,12 @@ module Win32
54
54
  @max_count = max_count
55
55
  @name = name
56
56
  @inherit = inherit
57
-
57
+
58
58
  # Used to prevent potential segfaults.
59
59
  if name && !name.is_a?(String)
60
60
  raise TypeError, 'name must be a string'
61
61
  end
62
-
62
+
63
63
  if inherit
64
64
  sec = 0.chr * 12 # sizeof(SECURITY_ATTRIBUTES)
65
65
  sec[0,4] = [12].pack('L')
@@ -67,15 +67,15 @@ module Win32
67
67
  else
68
68
  sec = 0
69
69
  end
70
-
70
+
71
71
  handle = CreateSemaphore(sec, initial_count, max_count, name)
72
-
72
+
73
73
  if handle == 0 || handle == INVALID_HANDLE_VALUE
74
74
  raise Error, get_last_error
75
75
  end
76
-
76
+
77
77
  super(handle)
78
-
78
+
79
79
  if block_given?
80
80
  begin
81
81
  yield self
@@ -128,12 +128,12 @@ module Win32
128
128
  pcount = [0].pack('L')
129
129
 
130
130
  unless ReleaseSemaphore(@handle, amount, pcount)
131
- raise Error, get_last_error
131
+ raise Error, get_last_error
132
132
  end
133
133
 
134
134
  pcount.unpack('L').first
135
135
  end
136
-
136
+
137
137
  # Returns whether or not the object was opened such that a process
138
138
  # created by the CreateProcess() function (a Windows API function) can
139
139
  # inherit the handle. The default is true.
@@ -1,70 +1,65 @@
1
1
  ################################################################
2
- # tc_semaphore.rb
2
+ # test_semaphore.rb
3
3
  #
4
4
  # Test suite for the win32-semaphore package. This test should
5
5
  # be run via the 'rake test' task.
6
6
  ################################################################
7
7
  require 'win32/semaphore'
8
- require 'test/unit'
8
+ require 'test-unit'
9
9
  include Win32
10
10
 
11
11
  class TC_Semaphore < Test::Unit::TestCase
12
- def setup
13
- @sem = Semaphore.new(1, 3, 'test')
14
- end
15
-
16
- def test_version
17
- assert_equal('0.3.1', Semaphore::VERSION)
18
- end
19
-
20
- def test_max_semaphore_name
21
- name = "foobar" * 500
22
- assert_raises(Semaphore::Error){ Semaphore.new(1, 1, name){} }
23
- end
24
-
25
- def test_open
26
- assert_respond_to(Semaphore, :open)
27
- assert_nothing_raised{ Semaphore.open('test'){} }
28
- assert_raises(Semaphore::Error){ Semaphore.open('bogus'){} }
29
- end
30
-
31
- def test_inheritable
32
- assert_respond_to(@sem, :inheritable?)
33
- assert_equal(true, @sem.inheritable?)
34
- end
35
-
36
- def test_release
37
- assert_respond_to(@sem, :release)
38
- assert_equal(1, @sem.release(1))
39
- assert_equal(2, @sem.release(1))
40
- assert_raises(Semaphore::Error){ @sem.release(99) }
41
- end
42
-
43
- def test_wait
44
- assert_respond_to(@sem, :wait)
45
- end
46
-
47
- def test_wait_any
48
- assert_respond_to(@sem, :wait_any)
49
- end
50
-
51
- def test_wait_all
52
- assert_respond_to(@sem, :wait_all)
53
- end
54
-
55
- def test_valid_constructor
56
- assert_nothing_raised{ Semaphore.new(0, 1){} }
57
- assert_nothing_raised{ Semaphore.new(0, 1, "foo"){} }
58
- assert_nothing_raised{ Semaphore.new(0, 1, "foo", false){} }
59
- end
60
-
61
- def test_invalid_constructor
62
- assert_raises(TypeError){ Semaphore.new("foo", "bar"){} }
63
- assert_raises(ArgumentError){ Semaphore.new(1, 1, "test", 1, 1){} }
64
- end
65
-
66
- def teardown
67
- @sem.close
68
- @sem = nil
69
- end
70
- end
12
+ def setup
13
+ @sem = Semaphore.new(1, 3, 'test')
14
+ end
15
+
16
+ def test_version
17
+ assert_equal('0.3.2', Semaphore::VERSION)
18
+ end
19
+
20
+ def test_open
21
+ assert_respond_to(Semaphore, :open)
22
+ assert_nothing_raised{ Semaphore.open('test'){} }
23
+ assert_raises(Semaphore::Error){ Semaphore.open('bogus'){} }
24
+ end
25
+
26
+ def test_inheritable
27
+ assert_respond_to(@sem, :inheritable?)
28
+ assert_equal(true, @sem.inheritable?)
29
+ end
30
+
31
+ def test_release
32
+ assert_respond_to(@sem, :release)
33
+ assert_equal(1, @sem.release(1))
34
+ assert_equal(2, @sem.release(1))
35
+ assert_raises(Semaphore::Error){ @sem.release(99) }
36
+ end
37
+
38
+ def test_wait
39
+ assert_respond_to(@sem, :wait)
40
+ end
41
+
42
+ def test_wait_any
43
+ assert_respond_to(@sem, :wait_any)
44
+ end
45
+
46
+ def test_wait_all
47
+ assert_respond_to(@sem, :wait_all)
48
+ end
49
+
50
+ def test_valid_constructor
51
+ assert_nothing_raised{ Semaphore.new(0, 1){} }
52
+ assert_nothing_raised{ Semaphore.new(0, 1, "foo"){} }
53
+ assert_nothing_raised{ Semaphore.new(0, 1, "foo", false){} }
54
+ end
55
+
56
+ def test_invalid_constructor
57
+ assert_raises(TypeError){ Semaphore.new("foo", "bar"){} }
58
+ assert_raises(ArgumentError){ Semaphore.new(1, 1, "test", 1, 1){} }
59
+ end
60
+
61
+ def teardown
62
+ @sem.close
63
+ @sem = nil
64
+ end
65
+ end
@@ -1,29 +1,26 @@
1
1
  require 'rubygems'
2
2
 
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'win32-semaphore'
5
- gem.version = '0.3.1'
6
- gem.author = 'Daniel J. Berger'
7
- gem.license = 'Artistic 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'Interface to MS Windows Semaphore objects.'
12
- gem.test_file = 'test/test_win32_semaphore.rb'
13
- gem.has_rdoc = true
14
- gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-semaphore'
5
+ spec.version = '0.3.2'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.github.com/djberg96/win32-semaphore'
10
+ spec.summary = 'Interface to MS Windows Semaphore objects.'
11
+ spec.test_file = 'test/test_win32_semaphore.rb'
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
15
13
 
16
- gem.rubyforge_project = 'win32utils'
17
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
14
+ spec.rubyforge_project = 'win32utils'
15
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
18
16
 
19
- gem.add_dependency('win32-ipc')
17
+ spec.add_dependency('win32-ipc')
18
+ spec.add_development_dependency('test-unit')
20
19
 
21
- gem.description = <<-EOF
22
- The win32-semaphore library provides an interface to semaphore objects
23
- on MS Windows. A semaphore is a kernel object used for resource counting.
24
- This allows threads to query the number of resources available, and wait
25
- if there aren't any available.
26
- EOF
20
+ spec.description = <<-EOF
21
+ The win32-semaphore library provides an interface to semaphore objects
22
+ on MS Windows. A semaphore is a kernel object used for resource counting.
23
+ This allows threads to query the number of resources available, and wait
24
+ if there aren't any available.
25
+ EOF
27
26
  end
28
-
29
- Gem::Builder.new(spec).build
metadata CHANGED
@@ -1,38 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: win32-semaphore
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Daniel J. Berger
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2009-08-11 00:00:00 -06:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: win32-ipc
16
+ requirement: &24606430 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
17
22
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- description: " The win32-semaphore library provides an interface to semaphore objects\n on MS Windows. A semaphore is a kernel object used for resource counting.\n This allows threads to query the number of resources available, and wait\n if there aren't any available.\n"
23
+ prerelease: false
24
+ version_requirements: *24606430
25
+ - !ruby/object:Gem::Dependency
26
+ name: test-unit
27
+ requirement: &24606160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *24606160
36
+ description: ! " The win32-semaphore library provides an interface to semaphore
37
+ objects\n on MS Windows. A semaphore is a kernel object used for resource counting.\n
38
+ \ This allows threads to query the number of resources available, and wait\n if
39
+ there aren't any available.\n"
26
40
  email: djberg96@gmail.com
27
41
  executables: []
28
-
29
42
  extensions: []
30
-
31
- extra_rdoc_files:
43
+ extra_rdoc_files:
32
44
  - README
33
45
  - CHANGES
34
46
  - MANIFEST
35
- files:
47
+ files:
36
48
  - CHANGES
37
49
  - examples/example_semaphore.rb
38
50
  - lib/win32/semaphore.rb
@@ -41,33 +53,30 @@ files:
41
53
  - README
42
54
  - test/test_win32_semaphore.rb
43
55
  - win32-semaphore.gemspec
44
- has_rdoc: true
45
- homepage: http://www.rubyforge.org/projects/win32utils
46
- licenses:
56
+ homepage: http://www.github.com/djberg96/win32-semaphore
57
+ licenses:
47
58
  - Artistic 2.0
48
59
  post_install_message:
49
60
  rdoc_options: []
50
-
51
- require_paths:
61
+ require_paths:
52
62
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
58
- version:
59
- required_rubygems_version: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
65
75
  requirements: []
66
-
67
76
  rubyforge_project: win32utils
68
- rubygems_version: 1.3.5
77
+ rubygems_version: 1.8.11
69
78
  signing_key:
70
79
  specification_version: 3
71
80
  summary: Interface to MS Windows Semaphore objects.
72
- test_files:
81
+ test_files:
73
82
  - test/test_win32_semaphore.rb