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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9e310b7b077bb24539719d830b79839dde4f00dc0634d4a2ccbb9e91809105a
4
- data.tar.gz: fffb72914195bd66e69ebb800fb0a2fe5bb0a39b79b3d73e912335e4fc968ce3
3
+ metadata.gz: 24a3b0989f0da6cc277c43d8b149534d800d83973865c8d1c91c2b6169f77752
4
+ data.tar.gz: 35f5187add508fb272933c27e8ac684b9f51c7cf79b5668e3cd1a440813811ee
5
5
  SHA512:
6
- metadata.gz: 1d1f9430aa04d71be97759004e36786de7f99aa845b6379d776718fc9adac65c486765a2ce6096ff4a22d4c273f14c5d40b4c128b782071b0a80c4ed4fc1fae3
7
- data.tar.gz: 03a01ad0f6fa2906d2934fcdc23ae12bef0b77448936de949d7422c61d6ec98d004b58648e31517e1edf5466ed6a33633958b92e6bb9ab6c28e885a2011f053e
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
- stopped = false
51
- watchdog = start_watchdog(Thread.current, -> { stopped })
50
+ stop = Thread::Queue.new
51
+ watchdog = start_watchdog(Thread.current, stop)
52
52
  begin
53
53
  block.call
54
54
  ensure
55
- stopped = true
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
- def start_watchdog(main_thread, stopped)
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
- until stopped.call
73
- sleep WATCHDOG_SLEEP_INTERVAL
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedisReadWriteLocks
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-read-write-locks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Umbrellio