redis-read-write-locks 0.5.0 → 0.5.1
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/lib/redis_read_write_locks/base_lock.rb +12 -7
- data/lib/redis_read_write_locks/version.rb +1 -1
- 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: 24a3b0989f0da6cc277c43d8b149534d800d83973865c8d1c91c2b6169f77752
|
|
4
|
+
data.tar.gz: 35f5187add508fb272933c27e8ac684b9f51c7cf79b5668e3cd1a440813811ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9934aca0a6fe1d618627278dd71b2e7fd81fcd3b951dacbca81bb590e33e6b37e3884ce60a3eb9513fb865ecd0c5b99ea20c70c23bcc1d6b19cd4dd18bab9478
|
|
7
|
+
data.tar.gz: 7ff1acbf8d1589a8596a19dd0c3e05a10868f24ac0dbc3adbc9010a7adb0add21441528066e62a8d0151904730def7e625143d882e559cfa3a3e9c1c8e6fcde7
|
|
@@ -47,12 +47,12 @@ module RedisReadWriteLocks
|
|
|
47
47
|
|
|
48
48
|
def synchronize(retry_count: nil, retry_delay: DEFAULT_RETRY_DELAY, &block)
|
|
49
49
|
acquire_or_raise(retry_count: retry_count, retry_delay: retry_delay)
|
|
50
|
-
|
|
51
|
-
watchdog = start_watchdog(Thread.current,
|
|
50
|
+
stop = Thread::Queue.new
|
|
51
|
+
watchdog = start_watchdog(Thread.current, stop)
|
|
52
52
|
begin
|
|
53
53
|
block.call
|
|
54
54
|
ensure
|
|
55
|
-
|
|
55
|
+
stop.close
|
|
56
56
|
watchdog.join
|
|
57
57
|
release
|
|
58
58
|
end
|
|
@@ -66,13 +66,18 @@ module RedisReadWriteLocks
|
|
|
66
66
|
acquire || raise(LockNotAcquiredError, "Could not acquire #{lock_type} lock '#{@name}'")
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
# Waits on the queue rather than sleeping, so closing it on release wakes the
|
|
70
|
+
# watchdog at once. While it slept, every synchronize paid up to a full
|
|
71
|
+
# WATCHDOG_SLEEP_INTERVAL on the way out - far more than a short critical
|
|
72
|
+
# section takes, and callers that take many brief locks paid it every time.
|
|
73
|
+
def start_watchdog(main_thread, stop)
|
|
70
74
|
Thread.new do
|
|
71
75
|
elapsed = 0.0
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
loop do
|
|
77
|
+
stop.pop(timeout: WATCHDOG_SLEEP_INTERVAL)
|
|
78
|
+
break if stop.closed?
|
|
79
|
+
|
|
74
80
|
elapsed += WATCHDOG_SLEEP_INTERVAL
|
|
75
|
-
next if stopped.call
|
|
76
81
|
next unless elapsed >= WATCHDOG_REFRESH_INTERVAL
|
|
77
82
|
|
|
78
83
|
elapsed = 0.0
|