futex 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/futex.gemspec +1 -1
  3. data/lib/futex.rb +10 -8
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ab0c6b23a6d358ef98795adc73b7b3ec9f9b9b9714dbce423b87a19199f3f00
4
- data.tar.gz: 98866fced75a607457dcfa6895f8d0d48f06573d4c6ccb10a806b6d58569ae82
3
+ metadata.gz: 047a5eec58f0138706f3e1ae934cccde006f2106a42859f6f0fce0371b7459fc
4
+ data.tar.gz: 9bd6d01c2f45511ede96555fa20b0cf0d7426873cfef1a0a4ac645d78f6d38a8
5
5
  SHA512:
6
- metadata.gz: df0638b0dd8f4cebce2ba7b20be4640f211ae2d6e22fb146cd5df1fe3671aa4a5804a6a91240826e4fc9d8a91f46052b30eed12cc8d29a82ce593df13c480acb
7
- data.tar.gz: 224cb207f548b50f5ec0226040123dab83b89d003d97cde03dbe6eb2b92fef9c3c671994df43ae328bd3302a59322a849ccbcd84c5aec6b4cc62113656faae35
6
+ metadata.gz: a959ddda978d3dc620b3dbcc5c2e780b6d47d1a9803a1c8aa4220037c7dca3319a703c5341b0f79407611ef775094f46f4fe9a5a6686a91ecb5867d1309c3929
7
+ data.tar.gz: b3e53ad7e41c7c04554930515f49d1acd912f07f8103554fd399e299cbb31164e960f3e5531be8408ce93d9eecf8facfa92ebb1d5cc8895bae8120e6a4b94937
@@ -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.2'
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'
@@ -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 "#{badge} can't get #{exclusive ? '' : 'non-'}exclusive access \
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("#{badge} still waiting for #{exclusive ? '' : 'non-'}exclusive
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 #{badge} in #{age(start)}: #{@path} \
90
- (attempt no.#{cycle})")
91
- File.write(@lock, badge)
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 #{badge} in #{age(acq)}: #{@path}")
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.2
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-21 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest