reentrant_mutex 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b626086142c3356ccc40d96a806e18f256778da
4
- data.tar.gz: 1b3a1dab63094ecca1ec176f0fbf42fcd060a484
3
+ metadata.gz: a33897ff9e7cea3a5cbcfa698bb12641ad024c50
4
+ data.tar.gz: ec2ce7e6d7f82c7c38b2cfb47ffd986218db4775
5
5
  SHA512:
6
- metadata.gz: 8fe2383a5392af05e16a85d14df729e323da501c64dd85789f63e56ca2798272f66ea9bbf61eee179abd16911b628dea3d3dd8a0d35c07ac6bb3eb98a742e212
7
- data.tar.gz: d049c9ed3f9eaa4286d79b8a41de3c5fd4e6de075d4fe835e38e010bcbee141df586e7c611bf4467789957bcdfb6cc9c4f48c8cd89013dfe968dd807bb97ab61
6
+ metadata.gz: fb58a48b1aea6294cc9cfe7522207c062b5692031a1c0556a430b72393d00cc80b8f111a84e29c4280e744f6d4e262f2f2afad471ca2445e3f2a2143d0a8ba6e
7
+ data.tar.gz: 2576e05e015ff280ab5ad6e3dace4ef376a0720883e23cf410a6b81034ddffc2ed3a5f775ce89c639f573866295cc61151a5ed4b38b95c4fe357f4a1c90f216a
@@ -9,11 +9,12 @@ class ReentrantMutex < Mutex
9
9
  def synchronize
10
10
  raise ThreadError, 'Must be called with a block' unless block_given?
11
11
 
12
- lock
13
- ret = yield
14
- unlock
15
-
16
- ret
12
+ begin
13
+ lock
14
+ yield
15
+ ensure
16
+ unlock
17
+ end
17
18
  end
18
19
 
19
20
  def lock
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'reentrant_mutex'
4
- spec.version = '1.1.0'
4
+ spec.version = '1.1.1'
5
5
  spec.authors = ['Boris Bera']
6
6
  spec.email = ['bboris@rsoft.ca']
7
7
  spec.summary = %q{A simple reentrant/recursive mutex}
@@ -20,6 +20,18 @@ describe ReentrantMutex do
20
20
  it 'should yield the block' do
21
21
  expect{|b| mutex.synchronize &b}.to yield_with_no_args
22
22
  end
23
+
24
+ it 'should leave the mutex unlocked' do
25
+ mutex.synchronize {}
26
+
27
+ expect(mutex.locked?).to be_false
28
+ end
29
+
30
+ it 'should be locked in the block' do
31
+ mutex.synchronize do
32
+ expect(mutex.locked?).to be_true
33
+ end
34
+ end
23
35
  end
24
36
 
25
37
  describe '#lock' do
@@ -27,6 +39,12 @@ describe ReentrantMutex do
27
39
  mutex.lock
28
40
  expect{mutex.lock}.not_to raise_error
29
41
  end
42
+
43
+ it 'should lock the mutex' do
44
+ mutex.lock
45
+
46
+ expect(mutex.locked?).to be_true
47
+ end
30
48
  end
31
49
 
32
50
  describe '#unlock' do
@@ -41,5 +59,12 @@ describe ReentrantMutex do
41
59
  expect{mutex.unlock}.not_to raise_error
42
60
  expect{mutex.unlock}.not_to raise_error
43
61
  end
62
+
63
+ it 'should unlock the mutex' do
64
+ mutex.lock
65
+ mutex.unlock
66
+
67
+ expect(mutex.locked?).to be_false
68
+ end
44
69
  end
45
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reentrant_mutex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Bera