Skip to content

Commit e46314e

Browse files
committed
[DOC] Monitor
1 parent c194357 commit e46314e

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

ext/monitor/lib/monitor.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ def broadcast
143143

144144
private
145145

146-
def initialize(monitor)
146+
def initialize(monitor) # :nodoc:
147147
@monitor = monitor
148148
@cond = Thread::ConditionVariable.new
149149
end
150150
end
151151

152-
def self.extend_object(obj)
152+
def self.extend_object(obj) # :nodoc:
153153
super(obj)
154154
obj.__send__(:mon_initialize)
155155
end
@@ -254,6 +254,10 @@ def mon_check_owner
254254
# end
255255
#
256256
class Monitor
257+
#
258+
# Creates a new MonitorMixin::ConditionVariable associated with the
259+
# Monitor object.
260+
#
257261
def new_cond
258262
::MonitorMixin::ConditionVariable.new(self)
259263
end

ext/monitor/monitor.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ mc_owner_p(struct rb_monitor *mc)
5656
return mc->owner == rb_fiber_current();
5757
}
5858

59+
/*
60+
* call-seq:
61+
* try_enter -> true or false
62+
*
63+
* Attempts to enter exclusive section. Returns +false+ if lock fails.
64+
*/
5965
static VALUE
6066
monitor_try_enter(VALUE monitor)
6167
{
@@ -72,6 +78,12 @@ monitor_try_enter(VALUE monitor)
7278
return Qtrue;
7379
}
7480

81+
/*
82+
* call-seq:
83+
* enter -> nil
84+
*
85+
* Enters exclusive section.
86+
*/
7587
static VALUE
7688
monitor_enter(VALUE monitor)
7789
{
@@ -85,6 +97,7 @@ monitor_enter(VALUE monitor)
8597
return Qnil;
8698
}
8799

100+
/* :nodoc: */
88101
static VALUE
89102
monitor_check_owner(VALUE monitor)
90103
{
@@ -95,6 +108,12 @@ monitor_check_owner(VALUE monitor)
95108
return Qnil;
96109
}
97110

111+
/*
112+
* call-seq:
113+
* exit -> nil
114+
*
115+
* Leaves exclusive section.
116+
*/
98117
static VALUE
99118
monitor_exit(VALUE monitor)
100119
{
@@ -112,13 +131,15 @@ monitor_exit(VALUE monitor)
112131
return Qnil;
113132
}
114133

134+
/* :nodoc: */
115135
static VALUE
116136
monitor_locked_p(VALUE monitor)
117137
{
118138
struct rb_monitor *mc = monitor_ptr(monitor);
119139
return rb_mutex_locked_p(mc->mutex);
120140
}
121141

142+
/* :nodoc: */
122143
static VALUE
123144
monitor_owned_p(VALUE monitor)
124145
{
@@ -166,6 +187,7 @@ monitor_enter_for_cond(VALUE v)
166187
return Qnil;
167188
}
168189

190+
/* :nodoc: */
169191
static VALUE
170192
monitor_wait_for_cond(VALUE monitor, VALUE cond, VALUE timeout)
171193
{
@@ -193,6 +215,14 @@ monitor_sync_ensure(VALUE monitor)
193215
return monitor_exit(monitor);
194216
}
195217

218+
/*
219+
* call-seq:
220+
* synchronize { } -> result of the block
221+
*
222+
* Enters exclusive section and executes the block. Leaves the exclusive
223+
* section automatically when the block exits. See example under
224+
* +MonitorMixin+.
225+
*/
196226
static VALUE
197227
monitor_synchronize(VALUE monitor)
198228
{

0 commit comments

Comments
 (0)