futex 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/futex.gemspec +1 -1
- data/lib/futex.rb +10 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 047a5eec58f0138706f3e1ae934cccde006f2106a42859f6f0fce0371b7459fc
|
4
|
+
data.tar.gz: 9bd6d01c2f45511ede96555fa20b0cf0d7426873cfef1a0a4ac645d78f6d38a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a959ddda978d3dc620b3dbcc5c2e780b6d47d1a9803a1c8aa4220037c7dca3319a703c5341b0f79407611ef775094f46f4fe9a5a6686a91ecb5867d1309c3929
|
7
|
+
data.tar.gz: b3e53ad7e41c7c04554930515f49d1acd912f07f8103554fd399e299cbb31164e960f3e5531be8408ce93d9eecf8facfa92ebb1d5cc8895bae8120e6a4b94937
|
data/futex.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.rubygems_version = '2.3.3'
|
32
32
|
s.required_ruby_version = '>=2.3'
|
33
33
|
s.name = 'futex'
|
34
|
-
s.version = '0.4.
|
34
|
+
s.version = '0.4.3'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'File-based mutex'
|
37
37
|
s.description = 'Ruby Gem for file-based locking'
|
data/lib/futex.rb
CHANGED
@@ -68,6 +68,8 @@ class Futex
|
|
68
68
|
FileUtils.mkdir_p(File.dirname(@lock))
|
69
69
|
step = (1 / @sleep).to_i
|
70
70
|
start = Time.now
|
71
|
+
prefix = exclusive ? '' : 'non-'
|
72
|
+
b = badge(exclusive)
|
71
73
|
File.open(@lock, File::CREAT | File::RDWR) do |f|
|
72
74
|
cycle = 0
|
73
75
|
loop do
|
@@ -77,31 +79,31 @@ class Futex
|
|
77
79
|
sleep(@sleep)
|
78
80
|
cycle += 1
|
79
81
|
if Time.now - start > @timeout
|
80
|
-
raise "#{
|
82
|
+
raise "#{b} can't get #{prefix}exclusive access \
|
81
83
|
to the file #{@path} because of the lock at #{@lock}, after #{age(start)} \
|
82
84
|
of waiting: #{IO.read(@lock)}"
|
83
85
|
end
|
84
86
|
if (cycle % step).zero? && Time.now - start > @timeout / 2
|
85
|
-
debug("#{
|
87
|
+
debug("#{b} still waiting for #{prefix}exclusive
|
86
88
|
access to #{@path}, #{age(start)} already: #{IO.read(@lock)}")
|
87
89
|
end
|
88
90
|
end
|
89
|
-
debug("Locked by #{
|
90
|
-
(attempt no.#{cycle})")
|
91
|
-
File.write(@lock,
|
91
|
+
debug("Locked by #{b} in #{age(start)}, #{prefix}exclusive: \
|
92
|
+
#{@path} (attempt no.#{cycle})")
|
93
|
+
File.write(@lock, b)
|
92
94
|
acq = Time.now
|
93
95
|
res = yield(@path)
|
94
|
-
debug("Unlocked by #{
|
96
|
+
debug("Unlocked by #{b} in #{age(acq)}, #{prefix}exclusive: #{@path}")
|
95
97
|
res
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
99
101
|
private
|
100
102
|
|
101
|
-
def badge
|
103
|
+
def badge(exclusive)
|
102
104
|
tname = Thread.current.name
|
103
105
|
tname = 'nil' if tname.nil?
|
104
|
-
"##{Process.pid}/#{tname}"
|
106
|
+
"##{Process.pid}-#{exclusive ? 'ex' : 'sh'}/#{tname}"
|
105
107
|
end
|
106
108
|
|
107
109
|
def age(time)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: futex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|