Skip to content

Commit d77142e

Browse files
committed
Use separate object for condition to match MRI class ancestry.
1 parent 6398c04 commit d77142e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/mri/monitor.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ module MonitorMixin
9898
# above calls while_wait and signal, this class should be documented.
9999
#
100100

101-
class ConditionVariable < ::ConditionVariable
101+
class ConditionVariable
102102

103103
#
104104
# Releases the lock held in the associated monitor and waits; reacquires the lock on wakeup.
@@ -107,7 +107,7 @@ class ConditionVariable < ::ConditionVariable
107107
# even if no other thread doesn't signal.
108108
#
109109
def wait(timeout = nil)
110-
super(@mon_mutex, timeout)
110+
@cond.wait(@mon_mutex, timeout)
111111
end
112112

113113
#
@@ -128,9 +128,30 @@ def wait_until
128128
end
129129
end
130130

131+
#
132+
# Wakes up the first thread in line waiting for this lock.
133+
#
134+
def signal
135+
check_owner
136+
@cond.signal
137+
end
138+
139+
#
140+
# Wakes up all threads waiting for this lock.
141+
#
142+
def broadcast
143+
check_owner
144+
@cond.broadcast
145+
end
146+
131147
private
132148

149+
def check_owner
150+
raise ThreadError, "current thread not owner" unless @mon_mutex.owned?
151+
end
152+
133153
def initialize(mutex)
154+
@cond = ::ConditionVariable.new
134155
@mon_mutex = mutex
135156
end
136157
end

0 commit comments

Comments
 (0)