@@ -5222,47 +5222,75 @@ rb_thread_flock(void *data)
5222
5222
return (VALUE )ret ;
5223
5223
}
5224
5224
5225
- /*
5225
+ /* :markup: markdown
5226
+ *
5226
5227
* call-seq:
5227
- * file.flock(locking_constant) -> 0 or false
5228
- *
5229
- * Locks or unlocks a file according to <i>locking_constant</i> (a
5230
- * logical <em>or</em> of the values in the table below).
5231
- * Returns <code>false</code> if File::LOCK_NB is specified and the
5232
- * operation would otherwise have blocked. Not available on all
5233
- * platforms.
5234
- *
5235
- * Locking constants (in class File):
5236
- *
5237
- * LOCK_EX | Exclusive lock. Only one process may hold an
5238
- * | exclusive lock for a given file at a time.
5239
- * ----------+------------------------------------------------
5240
- * LOCK_NB | Don't block when locking. May be combined
5241
- * | with other lock options using logical or.
5242
- * ----------+------------------------------------------------
5243
- * LOCK_SH | Shared lock. Multiple processes may each hold a
5244
- * | shared lock for a given file at the same time.
5245
- * ----------+------------------------------------------------
5246
- * LOCK_UN | Unlock.
5228
+ * flock(locking_constant) -> 0 or false
5229
+ *
5230
+ * Locks or unlocks a file according to the given `locking_constant`,
5231
+ * a bitwise OR of the values in the table below.
5232
+ *
5233
+ * Not available on all platforms.
5247
5234
*
5235
+ * Returns `false` if `File::LOCK_NB` is specified and the operation would have blocked;
5236
+ * otherwise returns `0`.
5237
+ * <br>
5238
+ *
5239
+ * <table>
5240
+ * <tr>
5241
+ * <th colspan="3">Locking Constants</th>
5242
+ * </tr>
5243
+ * <tr>
5244
+ * <th>Constant</th>
5245
+ * <th>Lock</th>
5246
+ * <th>Effect</th>
5247
+ * </tr>
5248
+ * <tr>
5249
+ * <td><tt>File::LOCK_EX</tt></td>
5250
+ * <td>Exclusive</td>
5251
+ * <td>Only one process may hold an exclusive lock for <tt>self</tt> at a time.</td>
5252
+ * </tr>
5253
+ * <tr>
5254
+ * <td><tt>File::LOCK_NB</tt></td>
5255
+ * <td>Non-blocking</td>
5256
+ * <td>
5257
+ * No blocking; may be combined with other `File::LOCK_SH` or `File::LOCK_EX`
5258
+ * using the bitwise OR operator <tt>|</tt>.
5259
+ * </td>
5260
+ * </tr>
5261
+ * <tr>
5262
+ * <td><tt>File::LOCK_SH</tt></td>
5263
+ * <td>Shared</td>
5264
+ * <td>Multiple processes may each hold a shared lock for <tt>self</tt> at the same time.</td>
5265
+ * </tr>
5266
+ * <tr>
5267
+ * <td><tt>File::LOCK_UN</tt></td>
5268
+ * <td>Unlock</td>
5269
+ * <td>Remove an existing lock held by this process.</td>
5270
+ * </tr>
5271
+ * </table>
5272
+ *
5273
+ * <br>
5248
5274
* Example:
5249
5275
*
5250
- * # update a counter using write lock
5251
- * # don't use "w" because it truncates the file before lock.
5252
- * File.open("counter", File::RDWR|File::CREAT, 0644) {|f|
5253
- * f.flock(File::LOCK_EX)
5254
- * value = f.read.to_i + 1
5255
- * f.rewind
5256
- * f.write("#{value}\n")
5257
- * f.flush
5258
- * f.truncate(f.pos)
5259
- * }
5260
- *
5261
- * # read the counter using read lock
5262
- * File.open("counter", "r") {|f|
5263
- * f.flock(File::LOCK_SH)
5264
- * p f.read
5265
- * }
5276
+ * ```ruby
5277
+ * # Update a counter using an exclusive lock.
5278
+ * # Don't use File::WRONLY because it truncates the file.
5279
+ * File.open('counter', File::RDWR | File::CREAT, 0644) do |f|
5280
+ * f.flock(File::LOCK_EX)
5281
+ * value = f.read.to_i + 1
5282
+ * f.rewind
5283
+ * f.write("#{value}\n")
5284
+ * f.flush
5285
+ * f.truncate(f.pos)
5286
+ * end
5287
+ *
5288
+ * # Read the counter using a shared lock.
5289
+ * File.open('counter', 'r') do |f|
5290
+ * f.flock(File::LOCK_SH)
5291
+ * f.read
5292
+ * end
5293
+ * ```
5266
5294
*
5267
5295
*/
5268
5296
0 commit comments