reentrant_mutex 1.0.0 → 1.1.0

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: b0824ae06f5a109d6437d7330f58bcf78d7394a7
4
- data.tar.gz: cd3d9f14e60c5be608a4ea82ef39e39fe8cd154d
3
+ metadata.gz: 4b626086142c3356ccc40d96a806e18f256778da
4
+ data.tar.gz: 1b3a1dab63094ecca1ec176f0fbf42fcd060a484
5
5
  SHA512:
6
- metadata.gz: 734e428dbe83f084e6b6112d46b15a194207b5bfc56544c9e9210f48862ead33f456c8635b51a82273b5ec34edec269cabd68e84dbcbdd6bd4499ece0216b4ed
7
- data.tar.gz: d83450b1e06cf49faccf752be0036e87176bc46947819c0672dcd5dec10cd5ee313690da31f67638a9e26c3178144ff2586f2198fe68f93f3d43bd4f2634e331
6
+ metadata.gz: 8fe2383a5392af05e16a85d14df729e323da501c64dd85789f63e56ca2798272f66ea9bbf61eee179abd16911b628dea3d3dd8a0d35c07ac6bb3eb98a742e212
7
+ data.tar.gz: d049c9ed3f9eaa4286d79b8a41de3c5fd4e6de075d4fe835e38e010bcbee141df586e7c611bf4467789957bcdfb6cc9c4f48c8cd89013dfe968dd807bb97ab61
@@ -6,6 +6,16 @@ class ReentrantMutex < Mutex
6
6
  super
7
7
  end
8
8
 
9
+ def synchronize
10
+ raise ThreadError, 'Must be called with a block' unless block_given?
11
+
12
+ lock
13
+ ret = yield
14
+ unlock
15
+
16
+ ret
17
+ end
18
+
9
19
  def lock
10
20
  c = increase_count Thread.current
11
21
  super if c <= 1
@@ -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.0.0'
4
+ spec.version = '1.1.0'
5
5
  spec.authors = ['Boris Bera']
6
6
  spec.email = ['bboris@rsoft.ca']
7
7
  spec.summary = %q{A simple reentrant/recursive mutex}
@@ -3,6 +3,25 @@ require 'spec_helper'
3
3
  describe ReentrantMutex do
4
4
  let(:mutex) { ReentrantMutex.new }
5
5
 
6
+ describe '#synchronize' do
7
+ it 'should raise an error when no block is given' do
8
+ expect{mutex.synchronize}.to raise_error
9
+ end
10
+
11
+ it 'should not raise an error when called twice' do
12
+ expect{mutex.synchronize{mutex.synchronize{}}}.not_to raise_error
13
+ end
14
+
15
+ it 'should return whatever the block returns' do
16
+ res = mutex.synchronize { 42 }
17
+ expect(res).to eql(42)
18
+ end
19
+
20
+ it 'should yield the block' do
21
+ expect{|b| mutex.synchronize &b}.to yield_with_no_args
22
+ end
23
+ end
24
+
6
25
  describe '#lock' do
7
26
  it 'should not deadlock when called twice' do
8
27
  mutex.lock
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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Bera