repo.or.cz
/
rainbows.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
Rainbows! 5.2.1
[rainbows.git]
/
lib
/
rainbows
/
sync_close.rb
blob
999f003779005a51009c6ab8c6cde55f86463ffe
1
# -*- encoding: binary -*-
2
# :enddoc:
3
require 'thread'
4
class Rainbows::SyncClose
5
def initialize(body)
6
@body = body
7
@mutex = Mutex.new
8
@cv = ConditionVariable.new
9
@mutex.synchronize do
10
yield self
11
@cv.wait(@mutex)
12
end
13
end
14
15
def respond_to?(m)
16
@body.respond_to?(m)
17
end
18
19
def to_path
20
@body.to_path
21
end
22
23
def each
24
@body.each { |x| yield x }
25
end
26
27
def to_io
28
@body.to_io
29
end
30
31
# called by the writer thread to wake up the original thread (in #initialize)
32
def close
33
@body.close
34
ensure
35
@mutex.synchronize { @cv.signal }
36
end
37
end