[DOC] Monitor
This commit is contained in:
parent
c194357c08
commit
e46314edd1
Notes:
git
2024-12-25 01:38:35 +00:00
@ -143,13 +143,13 @@ module MonitorMixin
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def initialize(monitor)
|
def initialize(monitor) # :nodoc:
|
||||||
@monitor = monitor
|
@monitor = monitor
|
||||||
@cond = Thread::ConditionVariable.new
|
@cond = Thread::ConditionVariable.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.extend_object(obj)
|
def self.extend_object(obj) # :nodoc:
|
||||||
super(obj)
|
super(obj)
|
||||||
obj.__send__(:mon_initialize)
|
obj.__send__(:mon_initialize)
|
||||||
end
|
end
|
||||||
@ -254,6 +254,10 @@ end
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class Monitor
|
class Monitor
|
||||||
|
#
|
||||||
|
# Creates a new MonitorMixin::ConditionVariable associated with the
|
||||||
|
# Monitor object.
|
||||||
|
#
|
||||||
def new_cond
|
def new_cond
|
||||||
::MonitorMixin::ConditionVariable.new(self)
|
::MonitorMixin::ConditionVariable.new(self)
|
||||||
end
|
end
|
||||||
|
@ -56,6 +56,12 @@ mc_owner_p(struct rb_monitor *mc)
|
|||||||
return mc->owner == rb_fiber_current();
|
return mc->owner == rb_fiber_current();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* try_enter -> true or false
|
||||||
|
*
|
||||||
|
* Attempts to enter exclusive section. Returns +false+ if lock fails.
|
||||||
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
monitor_try_enter(VALUE monitor)
|
monitor_try_enter(VALUE monitor)
|
||||||
{
|
{
|
||||||
@ -72,6 +78,12 @@ monitor_try_enter(VALUE monitor)
|
|||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* enter -> nil
|
||||||
|
*
|
||||||
|
* Enters exclusive section.
|
||||||
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
monitor_enter(VALUE monitor)
|
monitor_enter(VALUE monitor)
|
||||||
{
|
{
|
||||||
@ -85,6 +97,7 @@ monitor_enter(VALUE monitor)
|
|||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* :nodoc: */
|
||||||
static VALUE
|
static VALUE
|
||||||
monitor_check_owner(VALUE monitor)
|
monitor_check_owner(VALUE monitor)
|
||||||
{
|
{
|
||||||
@ -95,6 +108,12 @@ monitor_check_owner(VALUE monitor)
|
|||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* exit -> nil
|
||||||
|
*
|
||||||
|
* Leaves exclusive section.
|
||||||
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
monitor_exit(VALUE monitor)
|
monitor_exit(VALUE monitor)
|
||||||
{
|
{
|
||||||
@ -112,6 +131,7 @@ monitor_exit(VALUE monitor)
|
|||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* :nodoc: */
|
||||||
static VALUE
|
static VALUE
|
||||||
monitor_locked_p(VALUE monitor)
|
monitor_locked_p(VALUE monitor)
|
||||||
{
|
{
|
||||||
@ -119,6 +139,7 @@ monitor_locked_p(VALUE monitor)
|
|||||||
return rb_mutex_locked_p(mc->mutex);
|
return rb_mutex_locked_p(mc->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* :nodoc: */
|
||||||
static VALUE
|
static VALUE
|
||||||
monitor_owned_p(VALUE monitor)
|
monitor_owned_p(VALUE monitor)
|
||||||
{
|
{
|
||||||
@ -166,6 +187,7 @@ monitor_enter_for_cond(VALUE v)
|
|||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* :nodoc: */
|
||||||
static VALUE
|
static VALUE
|
||||||
monitor_wait_for_cond(VALUE monitor, VALUE cond, VALUE timeout)
|
monitor_wait_for_cond(VALUE monitor, VALUE cond, VALUE timeout)
|
||||||
{
|
{
|
||||||
@ -193,6 +215,14 @@ monitor_sync_ensure(VALUE monitor)
|
|||||||
return monitor_exit(monitor);
|
return monitor_exit(monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* synchronize { } -> result of the block
|
||||||
|
*
|
||||||
|
* Enters exclusive section and executes the block. Leaves the exclusive
|
||||||
|
* section automatically when the block exits. See example under
|
||||||
|
* +MonitorMixin+.
|
||||||
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
monitor_synchronize(VALUE monitor)
|
monitor_synchronize(VALUE monitor)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user