8000 [DOC] Clean up doc for File#flock by BurdetteLamar · Pull Request #9332 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

[DOC] Clean up doc for File#flock #9332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Dec 23, 2023
102 changes: 65 additions & 37 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -5222,47 +5222,75 @@ rb_thread_flock(void *data)
return (VALUE)ret;
}

/*
/* :markup: markdown
*
* call-seq:
* file.flock(locking_constant) -> 0 or false
*
* Locks or unlocks a file according to <i>locking_constant</i> (a
* logical <em>or</em> of the values in the table below).
* Returns <code>false</code> if File::LOCK_NB is specified and the
* operation would otherwise have blocked. Not available on all
* platforms.
*
* Locking constants (in class File):
*
* LOCK_EX | Exclusive lock. Only one process may hold an
* | exclusive lock for a given file at a time.
* ----------+------------------------------------------------
* LOCK_NB | Don't block when locking. May be combined
* | with other lock options using logical or.
* ----------+------------------------------------------------
* LOCK_SH | Shared lock. Multiple processes may each hold a
* | shared lock for a given file at the same time.
* ----------+------------------------------------------------
* LOCK_UN | Unlock.
* flock(locking_constant) -> 0 or false
*
* Locks or unlocks a file according to the given `locking_constant`,
* a bitwise OR of the values in the table below.
*
* Not available on all platforms.
*
* Returns `false` if `File::LOCK_NB` is specified and the operation would have blocked;
* otherwise returns `0`.
* <br>
*
* <table>
* <tr>
* <th colspan="3">Locking Constants</th>
* </tr>
* <tr>
* <th>Constant</th>
* <th>Lock</th>
* <th>Effect</th>
* </tr>
* <tr>
* <td><tt>File::LOCK_EX</tt></td>
* <td>Exclusive</td>
* <td>Only one process may hold an exclusive lock for <tt>self</tt> at a time.</td>
* </tr>
* <tr>
* <td><tt>File::LOCK_NB</tt></td>
* <td>Non-blocking</td>
* <td>
* No blocking; may be combined with other `File::LOCK_SH` or `File::LOCK_EX`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backticks don't work inside of HTML.

Suggested change
* No blocking; may be combined with other `File::LOCK_SH` or `File::LOCK_EX`
* No blocking; may be combined with other <tt>File::LOCK_SH</tt> or <tt>File::LOCK_EX</tt>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BurdetteLamar this doesn't appear to be fixed.

* using the bitwise OR operator <tt>|</tt>.
* </td>
* </tr>
* <tr>
* <td><tt>File::LOCK_SH</tt></td>
* <td>Shared</td>
* <td>Multiple processes may each hold a shared lock for <tt>self</tt> at the same time.</td>
* </tr>
* <tr>
* <td><tt>File::LOCK_UN</tt></td>
* <td>None</td>
* <td>No locking.</td>
* </tr>
* </table>
*
* <br>
* Example:
*
* # update a counter using write lock
* # don't use "w" because it truncates the file before lock.
* File.open("counter", File::RDWR|File::CREAT, 0644) {|f|
* f.flock(File::LOCK_EX)
* value = f.read.to_i + 1
* f.rewind
* f.write("#{value}\n")
* f.flush
* f.truncate(f.pos)
* }
*
* # read the counter using read lock
* File.open("counter", "r") {|f|
* f.flock(File::LOCK_SH)
* p f.read
* }
* ```ruby
* # Update a counter using an exclusive lock.
* # Don't use File::WRONLY because it truncates the file.
* File.open('counter', File::RDWR | File::CREAT, 0644) do |f|
* f.flock(File::LOCK_EX)
* value = f.read.to_i + 1
* f.rewind
* f.write("#{value}\n")
* f.flush
* f.truncate(f.pos)
* end
*
* # Read the counter using a shared lock.
* File.open('counter', 'r') do |f|
* f.flock(File::LOCK_SH)
* f.read
* end
* ```
*
*/

Expand Down
0