win32-mutex 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/README +9 -6
- data/Rakefile +1 -3
- data/examples/example_win32_mutex.rb +65 -0
- data/lib/win32/mutex.rb +21 -14
- data/test/{tc_mutex.rb → test_win32_mutex.rb} +18 -12
- data/win32-mutex.gemspec +29 -20
- metadata +87 -51
data/CHANGES
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.3.1 - 8-Aug-2009
|
2
|
+
* Changed license to Artistic 2.0.
|
3
|
+
* Updated the gemspec, including addition of license and description update.
|
4
|
+
* Renamed the test and example files.
|
5
|
+
* Added test-unit, win32-process and win32-mmap as development dependencies.
|
6
|
+
|
1
7
|
== 0.3.0 - 4-May-2007
|
2
8
|
* Now pure Ruby.
|
3
9
|
* Both the Mutex.new and Mutex.open methods now accept a block, and
|
data/README
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
win32-ipc 0.5.0 or later
|
6
6
|
|
7
7
|
== Installation
|
8
|
+
=== Gem Installation
|
9
|
+
gem install win32-mutex
|
10
|
+
=== Local Installation
|
8
11
|
rake test (optional)
|
9
12
|
rake install
|
10
13
|
|
@@ -21,12 +24,12 @@
|
|
21
24
|
The mutex.rb file contains inline RDoc documentation. If you installed
|
22
25
|
this file as a gem, then you have the docs.
|
23
26
|
|
24
|
-
For an example of win32-mutex in action, look at the
|
25
|
-
in the 'examples' directory. You can also run the 'examples' rake task.
|
27
|
+
For an example of win32-mutex in action, look at the example_win32_mutex.rb
|
28
|
+
file in the 'examples' directory. You can also run the 'examples' rake task.
|
26
29
|
|
27
30
|
== Notes
|
28
|
-
The Mutex class is a subclass of Win32::Ipc (win32-ipc). This
|
29
|
-
require's the win32-ipc
|
31
|
+
The Mutex class is a subclass of Win32::Ipc (win32-ipc). This library
|
32
|
+
require's the win32-ipc library internally (you don't need to explicitly
|
30
33
|
call it).
|
31
34
|
|
32
35
|
== Acknowledgements
|
@@ -37,10 +40,10 @@
|
|
37
40
|
project page at http://www.rubyforge.net/projects/win32utils
|
38
41
|
|
39
42
|
== License
|
40
|
-
|
43
|
+
Artistic 2.0
|
41
44
|
|
42
45
|
== Copyright
|
43
|
-
(C) 2003-
|
46
|
+
(C) 2003-2009 Daniel J. Berger, All Rights Reserved
|
44
47
|
|
45
48
|
== Warranty
|
46
49
|
This package is provided "as is" and without any express or
|
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/
|
18
|
+
ruby '-Ilib examples/example_win32_mutex.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_mutex.rb']
|
26
24
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
##############################################################
|
2
|
+
# example_win32_mutex.rb
|
3
|
+
#
|
4
|
+
# A test script for general futzing. Modify as you see fit.
|
5
|
+
# This test script requires win32-process and win32-mmap.
|
6
|
+
##############################################################
|
7
|
+
MUTEXNAME = "This is a very long name"
|
8
|
+
|
9
|
+
require 'win32/mutex'
|
10
|
+
require 'win32/process'
|
11
|
+
require 'win32/mmap'
|
12
|
+
include Win32
|
13
|
+
|
14
|
+
pid = Process.fork
|
15
|
+
|
16
|
+
# child_1
|
17
|
+
if pid.nil?
|
18
|
+
mm = MMap.open('test')
|
19
|
+
mx = Win32::Mutex.open(MUTEXNAME)
|
20
|
+
5.times{
|
21
|
+
mx.wait
|
22
|
+
puts "child_1 wait "
|
23
|
+
mm.gvalue += 123
|
24
|
+
sleep 1
|
25
|
+
mm.gvalue -= 123
|
26
|
+
mx.release
|
27
|
+
puts "child_1 release "
|
28
|
+
}
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
pid2 = Process.fork
|
33
|
+
|
34
|
+
# child_2
|
35
|
+
if pid2.nil?
|
36
|
+
mm = MMap.open('test')
|
37
|
+
mx = Win32::Mutex.open(MUTEXNAME)
|
38
|
+
4.times{
|
39
|
+
mx.wait
|
40
|
+
puts "child_2 wait "
|
41
|
+
mm.gvalue += 456
|
42
|
+
sleep 2
|
43
|
+
mm.gvalue -= 456
|
44
|
+
mx.release
|
45
|
+
puts "child_2 release "
|
46
|
+
}
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
#parent
|
51
|
+
mm = MMap.new(:size => 1024, :name => 'test', :inherit => true)
|
52
|
+
mm.gvalue = 5
|
53
|
+
mx = Win32::Mutex.new(false, MUTEXNAME)
|
54
|
+
|
55
|
+
3.times{
|
56
|
+
mx.wait
|
57
|
+
puts "parent wait"
|
58
|
+
sleep 5
|
59
|
+
printf("Value of GValue=%d\n", mm.gvalue)
|
60
|
+
mx.release
|
61
|
+
puts "parent release"
|
62
|
+
}
|
63
|
+
|
64
|
+
p Process.waitpid2(pid)
|
65
|
+
p Process.waitpid2(pid2)
|
data/lib/win32/mutex.rb
CHANGED
@@ -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 Mutex class encapsulates Windows mutex objects.
|
4
7
|
class Mutex < Ipc
|
5
8
|
|
6
9
|
# This is the error raised if any of the Mutex methods fail.
|
@@ -10,12 +13,12 @@ module Win32
|
|
10
13
|
extend Windows::Error
|
11
14
|
extend Windows::Handle
|
12
15
|
|
13
|
-
|
16
|
+
# The version of the win32-mutex library
|
17
|
+
VERSION = '0.3.1'
|
14
18
|
|
15
|
-
# The name of the
|
16
|
-
#
|
19
|
+
# The name of the mutex object.
|
17
20
|
attr_reader :name
|
18
|
-
|
21
|
+
|
19
22
|
# Creates and returns new Mutex object. If +name+ is omitted, the
|
20
23
|
# Mutex object is created without a name, i.e. it's anonymous.
|
21
24
|
#
|
@@ -33,8 +36,8 @@ module Win32
|
|
33
36
|
#
|
34
37
|
def initialize(initial_owner=false, name=nil, inherit=true)
|
35
38
|
@initial_owner = initial_owner
|
36
|
-
@name
|
37
|
-
@inherit
|
39
|
+
@name = name
|
40
|
+
@inherit = inherit
|
38
41
|
|
39
42
|
# Used to prevent potential segfaults.
|
40
43
|
if name && !name.is_a?(String)
|
@@ -63,7 +66,7 @@ module Win32
|
|
63
66
|
begin
|
64
67
|
yield self
|
65
68
|
ensure
|
66
|
-
close
|
69
|
+
close # From superclass
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
@@ -79,9 +82,6 @@ module Win32
|
|
79
82
|
# already exist.
|
80
83
|
#
|
81
84
|
# If you want "open or create" semantics, then use Mutex.new.
|
82
|
-
#--
|
83
|
-
# The OpenMutex() call here is strictly to force an error if the user
|
84
|
-
# tries to open a mutex that doesn't already exist.
|
85
85
|
#
|
86
86
|
def self.open(name, inherit=true, &block)
|
87
87
|
if name && !name.is_a?(String)
|
@@ -89,11 +89,18 @@ module Win32
|
|
89
89
|
end
|
90
90
|
|
91
91
|
bool = inherit ? 1 : 0
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
|
93
|
+
# The OpenMutex() call here is strictly to force an error if the user
|
94
|
+
# tries to open a mutex that doesn't already exist.
|
95
|
+
begin
|
96
|
+
handle = OpenMutex(MUTEX_ALL_ACCESS, bool, name)
|
97
|
+
|
98
|
+
if handle == 0 || handle == INVALID_HANDLE_VALUE
|
99
|
+
raise Error, get_last_error
|
100
|
+
end
|
101
|
+
ensure
|
102
|
+
CloseHandle(handle) if handle && handle > 0
|
95
103
|
end
|
96
|
-
CloseHandle(handle)
|
97
104
|
|
98
105
|
self.new(false, name, inherit, &block)
|
99
106
|
end
|
@@ -1,27 +1,33 @@
|
|
1
|
-
|
1
|
+
#######################################################################
|
2
2
|
# tc_Win32::Mutex.rb
|
3
3
|
#
|
4
|
-
# Test suite for the win32-Win32::Mutex package. This test suite
|
5
|
-
# be run via the 'rake test' task.
|
6
|
-
|
4
|
+
# Test suite for the win32-Win32::Mutex package. This test suite
|
5
|
+
# should be run via the 'rake test' task.
|
6
|
+
#######################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
7
10
|
require 'test/unit'
|
8
11
|
require 'win32/mutex'
|
9
12
|
|
10
13
|
class TC_Win32_Mutex < Test::Unit::TestCase
|
11
14
|
def setup
|
12
15
|
@mutex = Win32::Mutex.new(true, 'test')
|
13
|
-
@umutex = Win32::Mutex.new(false,
|
16
|
+
@umutex = Win32::Mutex.new(false, 'Ηελλας')
|
14
17
|
end
|
15
18
|
|
16
19
|
def test_version
|
17
|
-
assert_equal('0.3.
|
20
|
+
assert_equal('0.3.1', Win32::Mutex::VERSION)
|
18
21
|
end
|
19
22
|
|
20
23
|
def test_open
|
21
24
|
assert_respond_to(Win32::Mutex, :open)
|
22
|
-
assert_nothing_raised{ Win32::Mutex.open(
|
23
|
-
assert_nothing_raised{ Win32::Mutex.open(
|
24
|
-
|
25
|
+
assert_nothing_raised{ Win32::Mutex.open('test'){} }
|
26
|
+
assert_nothing_raised{ Win32::Mutex.open('Ηελλας'){} }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_open_expected_errors
|
30
|
+
assert_raise(Win32::Mutex::Error){ Win32::Mutex.open('bogus'){} }
|
25
31
|
end
|
26
32
|
|
27
33
|
def test_release
|
@@ -31,13 +37,13 @@ class TC_Win32_Mutex < Test::Unit::TestCase
|
|
31
37
|
|
32
38
|
def test_initial_owner
|
33
39
|
assert_respond_to(@mutex, :initial_owner?)
|
34
|
-
|
35
|
-
|
40
|
+
assert_true(@mutex.initial_owner?)
|
41
|
+
assert_false(@umutex.initial_owner?)
|
36
42
|
end
|
37
43
|
|
38
44
|
def test_inheritable
|
39
45
|
assert_respond_to(@mutex, :inheritable?)
|
40
|
-
|
46
|
+
assert_true(@mutex.inheritable?)
|
41
47
|
end
|
42
48
|
|
43
49
|
def test_wait
|
data/win32-mutex.gemspec
CHANGED
@@ -1,24 +1,33 @@
|
|
1
|
-
require
|
1
|
+
require 'rubygems'
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
|
-
gem.name
|
5
|
-
gem.version
|
6
|
-
gem.author
|
7
|
-
gem.
|
8
|
-
gem.
|
9
|
-
gem.
|
10
|
-
gem.
|
11
|
-
gem.
|
12
|
-
gem.test_file
|
13
|
-
gem.has_rdoc
|
14
|
-
gem.files
|
15
|
-
|
16
|
-
gem.
|
17
|
-
gem.extra_rdoc_files
|
18
|
-
gem.add_dependency("win32-ipc", ">= 0.5.0")
|
19
|
-
end
|
4
|
+
gem.name = 'win32-mutex'
|
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 Mutex objects.'
|
12
|
+
gem.test_file = 'test/test_win32_mutex.rb'
|
13
|
+
gem.has_rdoc = true
|
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
|
-
|
22
|
-
|
23
|
-
|
19
|
+
gem.add_dependency('win32-ipc', '>= 0.5.0')
|
20
|
+
|
21
|
+
gem.add_development_dependency('test-unit', '>= 2.0.3')
|
22
|
+
gem.add_development_dependency('win32-process', '>= 0.6.1')
|
23
|
+
gem.add_development_dependency('win32-mmap', '>= 0.2.2')
|
24
|
+
|
25
|
+
gem.description = <<-EOF
|
26
|
+
The win32-mutex library provides an interface for creating mutex objects
|
27
|
+
on MS Windows. A mutex object is a synchronization object whose state
|
28
|
+
is set to signaled when it is not owned by any thread, and non-signaled
|
29
|
+
when it is owned.
|
30
|
+
EOF
|
24
31
|
end
|
32
|
+
|
33
|
+
Gem::Builder.new(spec).build
|
metadata
CHANGED
@@ -1,67 +1,103 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.2
|
3
|
-
specification_version: 1
|
4
2
|
name: win32-mutex
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2007-05-04 00:00:00 -06:00
|
8
|
-
summary: Interface to MS Windows Mutex 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 Mutex 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
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
- test/tc_mutex.rb
|
35
|
-
- CHANGES
|
36
|
-
- CVS
|
37
|
-
- examples
|
38
|
-
- lib
|
39
|
-
- MANIFEST
|
40
|
-
- Rakefile
|
41
|
-
- README
|
42
|
-
- test
|
43
|
-
- win32-mutex.gemspec
|
44
|
-
test_files:
|
45
|
-
- test/tc_mutex.rb
|
46
|
-
rdoc_options: []
|
47
|
-
|
48
|
-
extra_rdoc_files:
|
49
|
-
- README
|
50
|
-
- CHANGES
|
51
|
-
- MANIFEST
|
52
|
-
executables: []
|
53
|
-
|
54
|
-
extensions: []
|
55
|
-
|
56
|
-
requirements: []
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
57
11
|
|
12
|
+
date: 2009-08-08 00:00:00 -06:00
|
13
|
+
default_executable:
|
58
14
|
dependencies:
|
59
15
|
- !ruby/object:Gem::Dependency
|
60
16
|
name: win32-ipc
|
17
|
+
type: :runtime
|
61
18
|
version_requirement:
|
62
|
-
version_requirements: !ruby/object:Gem::
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
20
|
requirements:
|
64
21
|
- - ">="
|
65
22
|
- !ruby/object:Gem::Version
|
66
23
|
version: 0.5.0
|
67
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: test-unit
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.3
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: win32-process
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.6.1
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: win32-mmap
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.2.2
|
54
|
+
version:
|
55
|
+
description: " The win32-mutex library provides an interface for creating mutex objects\n on MS Windows. A mutex object is a synchronization object whose state\n is set to signaled when it is not owned by any thread, and non-signaled\n when it is owned.\n"
|
56
|
+
email: djberg96@gmail.com
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- README
|
63
|
+
- CHANGES
|
64
|
+
- MANIFEST
|
65
|
+
files:
|
66
|
+
- CHANGES
|
67
|
+
- examples/example_win32_mutex.rb
|
68
|
+
- lib/win32/mutex.rb
|
69
|
+
- MANIFEST
|
70
|
+
- Rakefile
|
71
|
+
- README
|
72
|
+
- test/test_win32_mutex.rb
|
73
|
+
- win32-mutex.gemspec
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: http://www.rubyforge.org/projects/win32utils
|
76
|
+
licenses:
|
77
|
+
- Artistic 2.0
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project: win32utils
|
98
|
+
rubygems_version: 1.3.5
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Interface to MS Windows Mutex objects.
|
102
|
+
test_files:
|
103
|
+
- test/test_win32_mutex.rb
|