aboutsummaryrefslogtreecommitdiffstats
path: root/lib/monitor.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-06 03:56:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-06 03:56:38 +0000
commit287a34ae0dfc23e4158f67cb7783d239f202c368 (patch)
tree5e35d5b41aae961b37cf6632f60c42f51c7aa775 /lib/monitor.rb
parent9b52ae2e6491bb5d6c59e1799449f6268baf6f89 (diff)
downloadruby-287a34ae0dfc23e4158f67cb7783d239f202c368.tar.gz
* {ext,lib,test}/**/*.rb: removed trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/monitor.rb')
-rw-r--r--lib/monitor.rb36
1 files changed, 18 insertions, 18 deletions
diff --git a/lib/monitor.rb b/lib/monitor.rb
index 31234819b8..00d85fae52 100644
--- a/lib/monitor.rb
+++ b/lib/monitor.rb
@@ -12,11 +12,11 @@ You can freely distribute/modify this library.
This is a simple example.
require 'monitor.rb'
-
+
buf = []
buf.extend(MonitorMixin)
empty_cond = buf.new_cond
-
+
# consumer
Thread.start do
loop do
@@ -26,7 +26,7 @@ This is a simple example.
end
end
end
-
+
# producer
while line = ARGF.gets
buf.synchronize do
@@ -49,11 +49,11 @@ require 'thread'
# +include+. For example:
#
# require 'monitor'
-#
+#
# buf = []
# buf.extend(MonitorMixin)
# empty_cond = buf.new_cond
-#
+#
# # consumer
# Thread.start do
# loop do
@@ -63,7 +63,7 @@ require 'thread'
# end
# end
# end
-#
+#
# # producer
# while line = ARGF.gets
# buf.synchronize do
@@ -71,7 +71,7 @@ require 'thread'
# empty_cond.signal
# end
# end
-#
+#
# The consumer thread waits for the producer thread to push a line
# to buf while buf.empty?, and the producer thread (main thread)
# reads a line from ARGF and push it to buf, then call
@@ -86,7 +86,7 @@ module MonitorMixin
#
class ConditionVariable
class Timeout < Exception; end
-
+
def wait(timeout = nil)
if timeout
raise NotImplementedError, "timeout is not implemented yet"
@@ -100,33 +100,33 @@ module MonitorMixin
@monitor.send(:mon_enter_for_cond, count)
end
end
-
+
def wait_while
while yield
wait
end
end
-
+
def wait_until
until yield
wait
end
end
-
+
def signal
@monitor.send(:mon_check_owner)
@cond.signal
end
-
+
def broadcast
@monitor.send(:mon_check_owner)
@cond.broadcast
end
-
+
def count_waiters
raise NotImplementedError
end
-
+
private
def initialize(monitor)
@@ -134,12 +134,12 @@ module MonitorMixin
@cond = ::ConditionVariable.new
end
end
-
+
def self.extend_object(obj)
super(obj)
obj.send(:mon_initialize)
end
-
+
#
# Attempts to enter exclusive section. Returns +false+ if lock fails.
#
@@ -166,7 +166,7 @@ module MonitorMixin
end
@mon_count += 1
end
-
+
#
# Leaves exclusive section.
#
@@ -193,7 +193,7 @@ module MonitorMixin
end
end
alias synchronize mon_synchronize
-
+
#
# FIXME: This isn't documented in Nutshell.
#