Class: SyncOut

Inherits:
Object
  • Object
show all
Defined in:
lib/common/ext/stdout.rb

Class Method Summary collapse

Class Method Details

.convertConfNum(str) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/common/ext/stdout.rb', line 92

def self.convertConfNum(str)
  if Bake.options.syncedOutput
    while str.sub!(">>CONF_NUM<<", Bake::Blocks::Block.block_counter.to_s) do
      Bake::Blocks::Block.inc_block_counter
    end
  end
end

.discardStreamsObject



118
119
120
121
122
# File 'lib/common/ext/stdout.rb', line 118

def self.discardStreams()
  mutex.synchronize do
    Thread.current[:stdout] = Thread.current[:tmpStdout] ? Thread.current[:tmpStdout].pop : nil
  end
end

.flushOutputObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/common/ext/stdout.rb', line 70

def self.flushOutput
  mutex.synchronize do
    tmp = Thread.current[:stdout]
    if tmp.string.length > 0
      Thread.current[:stdout] = Thread.current[:tmpStdout][Thread.current[:tmpStdout].length-1]
      puts tmp.string
      tmp.reopen("")
      Thread.current[:stdout] = tmp
    end
  end
end

.mutexObject



66
67
68
# File 'lib/common/ext/stdout.rb', line 66

def self.mutex
  @@mutex ||= Mutex.new
end

.startStreamObject



82
83
84
85
86
87
88
89
90
# File 'lib/common/ext/stdout.rb', line 82

def self.startStream
  s = StringIO.new
  if Thread.current[:tmpStdout].nil?
    Thread.current[:tmpStdout] = [Thread.current[:stdout]]
  else
    Thread.current[:tmpStdout] << Thread.current[:stdout]
  end
  Thread.current[:stdout] = s
end

.stopStreamObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/common/ext/stdout.rb', line 100

def self.stopStream()
  mutex.synchronize do

    s = Thread.current[:stdout]
    return if s.nil?
    Thread.current[:stdout] = Thread.current[:tmpStdout] ? Thread.current[:tmpStdout].pop : nil

    if s.string.length > 0
      convertConfNum(s.string)
      puts s.string
      s.reopen("")
    end

  end

end