win32-semaphore 0.3.0 → 0.3.1

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.
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.3.1 - 11-Aug-2009
2
+ * Changed license to Artistic 2.0.
3
+ * The Semaphore.open method is now slightly more robust.
4
+ * Renamed the test and example files.
5
+ * Some gemspec updates, including license and description.
6
+
1
7
  == 0.3.0 - 3-May-2007
2
8
  * Now pure Ruby.
3
9
  * Added a Rakefile, with test, install and example tasks.
data/MANIFEST CHANGED
@@ -3,6 +3,6 @@
3
3
  * README
4
4
  * Rakefile
5
5
  * win32-semaphore.gemspec
6
- * examples/semaphore_test.rb
6
+ * examples/example_semaphore.rb
7
7
  * lib/win32/semaphore.rb
8
- * test/tc_semaphore.rb
8
+ * test/test_win32_semaphore.rb
data/README CHANGED
@@ -9,7 +9,7 @@
9
9
  rake install
10
10
 
11
11
  == Synopsis
12
- require "win32/semaphore"
12
+ require 'win32/semaphore'
13
13
  include Win32
14
14
 
15
15
  Semaphore.new(1, 5, 'test') do |sem|
@@ -18,7 +18,7 @@
18
18
  end
19
19
 
20
20
  == Documentation
21
- The event.rb file contains inline RDoc documentation. If you installed
21
+ The semaphore.rb file contains inline RDoc documentation. If you installed
22
22
  this file as a gem, then you have the docs.
23
23
 
24
24
  For more detailed documentation about Semaphores on MS Windows in general,
@@ -42,10 +42,10 @@
42
42
  Suggestions welcome.
43
43
 
44
44
  == License
45
- Ruby's
45
+ Artistic 2.0
46
46
 
47
47
  == Copyright
48
- (C) 2003-2007 Daniel J. Berger
48
+ (C) 2003-2009 Daniel J. Berger
49
49
  All Rights Reserved
50
50
 
51
51
  == Warranty
data/Rakefile CHANGED
@@ -15,12 +15,10 @@ end
15
15
 
16
16
  desc 'Run the example program'
17
17
  task :example do
18
- ruby '-Ilib examples/semaphore_test.rb'
18
+ ruby '-Ilib examples/example_semaphore.rb'
19
19
  end
20
20
 
21
21
  Rake::TestTask.new do |t|
22
- t.libs << 'test'
23
22
  t.verbose = true
24
23
  t.warning = true
25
- t.test_files = FileList['test/tc_semaphore.rb']
26
24
  end
@@ -0,0 +1,40 @@
1
+ ##############################################################
2
+ # example_semaphore.rb
3
+ #
4
+ # A test script for general futzing. Modify as you see fit.
5
+ #
6
+ # Note that you can run this via the 'rake example' task.
7
+ ##############################################################
8
+ require "win32/semaphore"
9
+ include Win32
10
+
11
+ test = 1
12
+ s = Semaphore.new(3,3,"test")
13
+ test += 1
14
+ puts "ok #{test}"
15
+
16
+ print 'not ' unless s.wait(10) > 0
17
+ test += 1
18
+ puts "ok #{test}"
19
+
20
+ print 'not ' unless s.wait(0) > 0
21
+ test += 1
22
+ puts "ok #{test}"
23
+
24
+ printf "If you don't see 'ok %d' immediately, you'd better hit Ctrl-C\n", test+1
25
+ print 'not ' unless s.wait > 0
26
+ test += 1
27
+ puts "ok #{test}"
28
+
29
+ print 'not ' if s.wait(0) > 0
30
+ test += 1
31
+ puts "ok #{test}"
32
+
33
+ s.release
34
+ s.release(1)
35
+
36
+ print 'not ' unless (result = s.release(1)) == 2
37
+ test += 1
38
+ puts "ok #{test}\t(result is #{result})"
39
+
40
+ s.close
@@ -1,6 +1,9 @@
1
1
  require 'win32/ipc'
2
2
 
3
+ # The Win32 module serves as a namespace only.
3
4
  module Win32
5
+
6
+ # The Semaphore class encapsulates semaphore objects on Windows.
4
7
  class Semaphore < Ipc
5
8
 
6
9
  # This is the error raised if any of the Semaphore methods fail.
@@ -10,7 +13,8 @@ module Win32
10
13
  extend Windows::Error
11
14
  extend Windows::Handle
12
15
 
13
- VERSION = '0.3.0'
16
+ # The version of the win32-semaphore library
17
+ VERSION = '0.3.1'
14
18
 
15
19
  # The initial count for the semaphore object. This value must be greater
16
20
  # than or equal to zero and less than or equal to +max_count+. The state
@@ -92,21 +96,25 @@ module Win32
92
96
  # the semaphore doesn't already exist.
93
97
  #
94
98
  # If you want "open or create" semantics, then use Semaphore.new.
95
- #--
96
- # The OpenSemaphore() call here is strictly to force an error if the user
97
- # tries to open a semaphore that doesn't already exist.
98
99
  #
99
100
  def self.open(name, inherit=true, &block)
100
101
  if name && !name.is_a?(String)
101
102
  raise TypeError, 'name must be a string'
102
103
  end
103
-
104
+
104
105
  bool = inherit ? 1 : 0
105
- handle = OpenSemaphore(EVENT_ALL_ACCESS, bool, name)
106
- if handle == 0 || handle == INVALID_HANDLE_VALUE
107
- raise Error, get_last_error
106
+
107
+ # The OpenSemaphore() call here is strictly to force an error if the
108
+ # user tries to open a semaphore that doesn't already exist.
109
+ begin
110
+ handle = OpenSemaphore(SEMAPHORE_ALL_ACCESS, bool, name)
111
+
112
+ if handle == 0 || handle == INVALID_HANDLE_VALUE
113
+ raise Error, get_last_error
114
+ end
115
+ ensure
116
+ CloseHandle(handle)
108
117
  end
109
- CloseHandle(handle)
110
118
 
111
119
  self.new(0, 1, name, inherit, &block)
112
120
  end
@@ -118,9 +126,11 @@ module Win32
118
126
  #
119
127
  def release(amount = 1)
120
128
  pcount = [0].pack('L')
129
+
121
130
  unless ReleaseSemaphore(@handle, amount, pcount)
122
131
  raise Error, get_last_error
123
132
  end
133
+
124
134
  pcount.unpack('L').first
125
135
  end
126
136
 
@@ -14,7 +14,7 @@ class TC_Semaphore < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_version
17
- assert_equal('0.3.0', Semaphore::VERSION)
17
+ assert_equal('0.3.1', Semaphore::VERSION)
18
18
  end
19
19
 
20
20
  def test_max_semaphore_name
@@ -1,24 +1,29 @@
1
- require "rubygems"
1
+ require 'rubygems'
2
2
 
3
3
  spec = Gem::Specification.new do |gem|
4
- gem.name = "win32-semaphore"
5
- gem.version = "0.3.0"
6
- gem.author = "Daniel J. Berger"
7
- gem.email = "djberg96@gmail.com"
8
- gem.homepage = "http://www.rubyforge.org/projects/win32utils"
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'
9
10
  gem.platform = Gem::Platform::RUBY
10
- gem.summary = "Interface to MS Windows Semaphore objects."
11
- gem.description = "Interface to MS Windows Semaphore objects."
12
- gem.test_file = "test/tc_semaphore.rb"
11
+ gem.summary = 'Interface to MS Windows Semaphore objects.'
12
+ gem.test_file = 'test/test_win32_semaphore.rb'
13
13
  gem.has_rdoc = true
14
- gem.files = Dir["lib/win32/*.rb"] + Dir["test/*"] + Dir["[A-Z]*"]
15
- gem.files.reject! { |fn| fn.include? "CVS" }
16
- gem.require_path = "lib"
17
- gem.extra_rdoc_files = ["README", "CHANGES", "MANIFEST"]
18
- gem.add_dependency("win32-ipc", ">= 0.5.0")
19
- end
14
+ gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
15
+
16
+ gem.rubyforge_project = 'win32utils'
17
+ gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
20
18
 
21
- if $0 == __FILE__
22
- Gem.manage_gems
23
- Gem::Builder.new(spec).build
19
+ gem.add_dependency('win32-ipc')
20
+
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
24
27
  end
28
+
29
+ Gem::Builder.new(spec).build
metadata CHANGED
@@ -1,68 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: win32-semaphore
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-05-03 00:00:00 -06:00
8
- summary: Interface to MS Windows Semaphore objects.
9
- require_paths:
10
- - lib
11
- email: djberg96@gmail.com
12
- homepage: http://www.rubyforge.org/projects/win32utils
13
- rubyforge_project:
14
- description: Interface to MS Windows Semaphore objects.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.3.1
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Daniel J. Berger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-11 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: win32-ipc
17
+ 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"
26
+ email: djberg96@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - CHANGES
34
+ - MANIFEST
31
35
  files:
32
- - lib/win32/semaphore.rb
33
- - test/CVS
34
- - test/tc_semaphore.rb
35
36
  - CHANGES
36
- - CVS
37
- - doc
38
- - examples
39
- - lib
37
+ - examples/example_semaphore.rb
38
+ - lib/win32/semaphore.rb
40
39
  - MANIFEST
41
40
  - Rakefile
42
41
  - README
43
- - test
42
+ - test/test_win32_semaphore.rb
44
43
  - win32-semaphore.gemspec
45
- test_files:
46
- - test/tc_semaphore.rb
44
+ has_rdoc: true
45
+ homepage: http://www.rubyforge.org/projects/win32utils
46
+ licenses:
47
+ - Artistic 2.0
48
+ post_install_message:
47
49
  rdoc_options: []
48
50
 
49
- extra_rdoc_files:
50
- - README
51
- - CHANGES
52
- - MANIFEST
53
- executables: []
54
-
55
- extensions: []
56
-
51
+ require_paths:
52
+ - 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:
57
65
  requirements: []
58
66
 
59
- dependencies:
60
- - !ruby/object:Gem::Dependency
61
- name: win32-ipc
62
- version_requirement:
63
- version_requirements: !ruby/object:Gem::Version::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 0.5.0
68
- version:
67
+ rubyforge_project: win32utils
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Interface to MS Windows Semaphore objects.
72
+ test_files:
73
+ - test/test_win32_semaphore.rb