Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/timeout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Request

def initialize(thread, timeout, exception_class, message)
@thread = thread
@deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout
@deadline = GET_TIME.call(Process::CLOCK_MONOTONIC) + timeout
@exception_class = exception_class
@message = message

Expand Down Expand Up @@ -109,7 +109,7 @@ def self.create_timeout_thread

now = 0.0
QUEUE_MUTEX.synchronize do
while (now = Process.clock_gettime(Process::CLOCK_MONOTONIC)) < closest_deadline and QUEUE.empty?
while (now = GET_TIME.call(Process::CLOCK_MONOTONIC)) < closest_deadline and QUEUE.empty?
CONDVAR.wait(QUEUE_MUTEX, closest_deadline - now)
end
end
Expand All @@ -134,6 +134,12 @@ def self.ensure_timeout_thread_created
end
end
end

# We keep a private reference so that time mocking libraries won't break
# Timeout.
GET_TIME = Process.method(:clock_gettime)
private_constant :GET_TIME

# :startdoc:

# Perform an operation in a block, raising an error if it takes longer than
Expand Down