Module: XThread::RBMonitorMixin

Included in:
RBMonitor
Defined in:
lib/xthread/monitor.rb

Defined Under Namespace

Classes: RBConditionVariable

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extend_object(obj) ⇒ Object



153
154
155
156
# File 'lib/xthread/monitor.rb', line 153

def self.extend_object(obj)
  super(obj)
  obj.__send__(:mon_initialize)
end

Instance Method Details

#mon_enterObject

Enters exclusive section.



177
178
179
180
181
182
183
# File 'lib/xthread/monitor.rb', line 177

def mon_enter
  if @mon_owner != Thread.current
	@mon_mutex.lock
	@mon_owner = Thread.current
  end
  @mon_count += 1
end

#mon_exitObject

Leaves exclusive section.



188
189
190
191
192
193
194
195
# File 'lib/xthread/monitor.rb', line 188

def mon_exit
  mon_check_owner
  @mon_count -=1
  if @mon_count == 0
	@mon_owner = nil
	@mon_mutex.unlock
  end
end

#mon_synchronizeObject Also known as: synchronize

Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits. See example under MonitorMixin.



202
203
204
205
206
207
208
209
# File 'lib/xthread/monitor.rb', line 202

def mon_synchronize
  mon_enter
  begin
	yield
  ensure
	mon_exit
  end
end

#mon_try_enterObject Also known as: try_mon_enter

Attempts to enter exclusive section. Returns false if lock fails.



161
162
163
164
165
166
167
168
169
170
# File 'lib/xthread/monitor.rb', line 161

def mon_try_enter
  if @mon_owner != Thread.current
	unless @mon_mutex.try_lock
	  return false
	end
	@mon_owner = Thread.current
  end
  @mon_count += 1
  return true
end

#new_condObject

Creates a new MonitorMixin::ConditionVariable associated with the receiver.



216
217
218
# File 'lib/xthread/monitor.rb', line 216

def new_cond
  return RBConditionVariable.new(self)
end