Module: MonitorMixin

Included in:
Empathy::EM::Monitor, Monitor
Defined in:
lib/monitor.rb

Overview

See MRI Ruby's MonitorMixin This file is derived from MRI Ruby 1.9.3 monitor.rb

Copyright (C) 2001 Shugo Maeda [email protected]

The only changes are constant lookups, it dynamically uses thread constants from the included class/extended object

Note this relaces monitor.rb defined by ruby - so even if you don't include empathy you may end up using this module.

Defined Under Namespace

Classes: ConditionVariable

Instance Method Summary collapse

Instance Method Details

#mon_entervoid

This method returns an undefined value.

Enters exclusive section.



102
103
104
105
106
107
108
# File 'lib/monitor.rb', line 102

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

#mon_exitvoid

This method returns an undefined value.

Leaves exclusive section.



114
115
116
117
118
119
120
121
# File 'lib/monitor.rb', line 114

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

#mon_synchronizevoid Also known as: synchronize

This method returns an undefined value.

Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits.



127
128
129
130
131
132
133
134
# File 'lib/monitor.rb', line 127

def mon_synchronize
  mon_enter
  begin
    yield
  ensure
    mon_exit
  end
end

#mon_try_enterBoolean Also known as: try_mon_enter

Attempts to enter exclusive section.

Returns:

  • (Boolean)

    whether entry was successful



85
86
87
88
89
90
91
92
93
94
# File 'lib/monitor.rb', line 85

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

#new_condConditionVariable

Returns a new condition variable associated with the receiver.

Returns:



140
141
142
# File 'lib/monitor.rb', line 140

def new_cond
  return ConditionVariable.new(self)
end