futex 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/futex.gemspec +1 -1
- data/lib/futex.rb +12 -4
- data/test/test_futex.rb +1 -0
- 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: e077d8eafaa333121b04b808c43d91a7e8e5a7704bfd33ed82be8f978d3748bf
|
4
|
+
data.tar.gz: 05a7e8ed6eca0572f930a678fc933175c07e6c96a261e27e4b5fa75ccb3f7130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b5b11770396e1fe729dffd41f33c0fb0328760ada247b749969083b74076207d36e0e3c805234a88169a30e71d1b419e92c01ba1e884022d8df259df4135112
|
7
|
+
data.tar.gz: 8647c6a0277f269b38ee43085db288c61d6f49d18d4d09df186aaa22214168dd2e8d9dc1e81e46197f9c274df6592abf4eac08d867e58d8c6468dd92ffbe8e32
|
data/.rubocop.yml
CHANGED
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.
|
34
|
+
s.version = '0.8.0'
|
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
@@ -54,8 +54,16 @@ require 'time'
|
|
54
54
|
# License:: MIT
|
55
55
|
class Futex
|
56
56
|
# Exception that is raised when we can't lock because of some other
|
57
|
-
# process that is holding the lock now.
|
58
|
-
|
57
|
+
# process that is holding the lock now. There is an encapsulated
|
58
|
+
# <tt>start</tt> attribute of type <tt>Time</tt>, which points to the time
|
59
|
+
# when we started to try to acquire lock.
|
60
|
+
class CantLock < StandardError
|
61
|
+
attr_reader :start
|
62
|
+
def initialize(msg, start)
|
63
|
+
@start = start
|
64
|
+
super(msg)
|
65
|
+
end
|
66
|
+
end
|
59
67
|
|
60
68
|
# Creates a new instance of the class.
|
61
69
|
def initialize(path, log: STDOUT, timeout: 16, sleep: 0.005,
|
@@ -100,9 +108,9 @@ class Futex
|
|
100
108
|
Thread.current.thread_variable_set(:futex_cycle, cycle)
|
101
109
|
Thread.current.thread_variable_set(:futex_time, Time.now - start)
|
102
110
|
if Time.now - start > @timeout
|
103
|
-
raise CantLock
|
111
|
+
raise CantLock.new("#{b} can't get #{prefix}exclusive access \
|
104
112
|
to the file #{@path} because of the lock at #{@lock}, after #{age(start)} \
|
105
|
-
of waiting: #{IO.read(@lock)} (modified #{age(File.mtime(@lock))} ago)"
|
113
|
+
of waiting: #{IO.read(@lock)} (modified #{age(File.mtime(@lock))} ago)", start)
|
106
114
|
end
|
107
115
|
next unless (cycle % step).zero? && Time.now - start > @timeout / 2
|
108
116
|
debug("#{b} still waiting for #{prefix}exclusive \
|
data/test/test_futex.rb
CHANGED
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
|
+
version: 0.8.0
|
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-12-
|
11
|
+
date: 2018-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|