Module: MonitorMixin
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Defined in: | ext/monitor/lib/monitor.rb |
Class Method Summary
Instance Attribute Summary
-
#mon_locked? ⇒ Boolean
readonly
Returns true if this monitor is locked by any thread.
-
#mon_owned? ⇒ Boolean
readonly
Returns true if this monitor is locked by current thread.
Instance Method Summary
-
#mon_enter
Enters exclusive section.
-
#mon_exit
Leaves exclusive section.
-
#mon_synchronize(&b)
(also: #synchronize)
Enters exclusive section and executes the block.
-
#mon_try_enter
(also: #try_mon_enter)
Attempts to enter exclusive section.
-
#new_cond
Creates a new
ConditionVariable
associated with the::Monitor
object. -
#synchronize(&b)
Alias for #mon_synchronize.
-
#try_mon_enter
Alias for #mon_try_enter.
-
#initialize(*args)
private
Use
extend MonitorMixin
orinclude MonitorMixin
instead of this constructor. - #mon_check_owner private
-
#mon_initialize
private
Initializes the
MonitorMixin
after being included in a class or when an object has been extended with theMonitorMixin
.
Class Method Details
.extend_object(obj)
[ GitHub ]# File 'ext/monitor/lib/monitor.rb', line 153
def self.extend_object(obj) super(obj) obj.__send__(:mon_initialize) end
Instance Attribute Details
#mon_locked? ⇒ Boolean
(readonly)
Returns true if this monitor is locked by any thread
# File 'ext/monitor/lib/monitor.rb', line 185
def mon_locked? @mon_data.mon_locked? end
#mon_owned? ⇒ Boolean
(readonly)
Returns true if this monitor is locked by current thread.
# File 'ext/monitor/lib/monitor.rb', line 192
def mon_owned? @mon_data.mon_owned? end
Instance Method Details
#initialize(*args) (private)
Use extend MonitorMixin
or include MonitorMixin
instead of this constructor. Have look at the examples above to understand how to use this module.
# File 'ext/monitor/lib/monitor.rb', line 223
def initialize(*args) super mon_initialize end
#mon_check_owner (private)
[ GitHub ]# File 'ext/monitor/lib/monitor.rb', line 242
def mon_check_owner @mon_data.mon_check_owner end
#mon_enter
Enters exclusive section.
# File 'ext/monitor/lib/monitor.rb', line 170
def mon_enter @mon_data.enter end
#mon_exit
Leaves exclusive section.
# File 'ext/monitor/lib/monitor.rb', line 177
def mon_exit mon_check_owner @mon_data.exit end
#mon_initialize (private)
Initializes the MonitorMixin
after being included in a class or when an object has been extended with the MonitorMixin
# File 'ext/monitor/lib/monitor.rb', line 230
def mon_initialize if defined?(@mon_data) if defined?(@mon_initialized_by_new_cond) return # already initalized. elsif @mon_data_owner_object_id == self.object_id raise ThreadError, "already initialized" end end @mon_data = ::Monitor.new @mon_data_owner_object_id = self.object_id end
#mon_synchronize(&b) Also known as: #synchronize
Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits. See example under MonitorMixin
.
# File 'ext/monitor/lib/monitor.rb', line 201
def mon_synchronize(&b) @mon_data.synchronize(&b) end
#mon_try_enter Also known as: #try_mon_enter
Attempts to enter exclusive section. Returns false
if lock fails.
# File 'ext/monitor/lib/monitor.rb', line 161
def mon_try_enter @mon_data.try_enter end
#new_cond
Creates a new ::MonitorMixin::ConditionVariable
associated with the ::Monitor
object.
# File 'ext/monitor/lib/monitor.rb', line 210
def new_cond unless defined?(@mon_data) mon_initialize @mon_initialized_by_new_cond = true end return ConditionVariable.new(@mon_data) end
#synchronize(&b)
Alias for #mon_synchronize.
# File 'ext/monitor/lib/monitor.rb', line 204
alias synchronize mon_synchronize
#try_mon_enter
Alias for #mon_try_enter.
# File 'ext/monitor/lib/monitor.rb', line 165
alias try_mon_enter mon_try_enter