futex 0.8.3 → 0.8.4
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 +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 304cc67b805690f790a453273a62956b240d871b35aceb85fd3914b0a844f419
|
4
|
+
data.tar.gz: 777127ff698b47ac49d6477ad753cbad9479c62cf57951eeb05dc4fa83da3ad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96cc04db67df9cc3560639369e0b0715cec5c61483e107235c27ebd5efd33063812675d0d96323fc9928b6d7854d5bc810b5bf05a6e7b0bb68b0857fb209123b
|
7
|
+
data.tar.gz: 7ac2732a0196fceb094b9381dc7dad8e18dcbae6dc8ba55878c1fa4e2a465c0423c999bcb75f5b4df5295425b9c519698b1a719513d8c46471b01d376418de94
|
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.8.
|
34
|
+
s.version = '0.8.4'
|
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
@@ -124,7 +124,7 @@ access to #{@path}, #{age(start)} already: #{IO.read(@lock)} \
|
|
124
124
|
end
|
125
125
|
debug("Locked by #{b} in #{age(start)}, #{prefix}exclusive: \
|
126
126
|
#{@path} (attempt no.#{cycle})")
|
127
|
-
|
127
|
+
IO.write(@lock, b)
|
128
128
|
acq = Time.now
|
129
129
|
res = block_given? ? yield(@path) : nil
|
130
130
|
debug("Unlocked by #{b} in #{age(acq)}, #{prefix}exclusive: #{@path}")
|
@@ -168,21 +168,21 @@ access to #{@path}, #{age(start)} already: #{IO.read(@lock)} \
|
|
168
168
|
file = nil
|
169
169
|
synchronized do |counts|
|
170
170
|
file = File.open(path, File::CREAT | File::RDWR)
|
171
|
-
refs = deserialize(
|
171
|
+
refs = deserialize(IO.read(counts.path))
|
172
172
|
refs[path] = (refs[path] || 0) + 1
|
173
|
-
|
173
|
+
IO.write(counts.path, serialize(refs))
|
174
174
|
end
|
175
175
|
yield file
|
176
176
|
ensure
|
177
177
|
synchronized do |counts|
|
178
|
-
file
|
179
|
-
refs = deserialize(
|
178
|
+
file&.close
|
179
|
+
refs = deserialize(IO.read(counts.path))
|
180
180
|
refs[path] -= 1
|
181
181
|
if refs[path].zero?
|
182
182
|
FileUtils.rm(path, force: true)
|
183
183
|
refs.delete(path)
|
184
184
|
end
|
185
|
-
|
185
|
+
IO.write(counts.path, serialize(refs))
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|