FileRwLock separate "exclusive" from "exclusive+write"
commit0bf808343fae16d5bddfdb4a3d9fb621e2f6520a
authorLucian Wischik <ljw@meta.com>
Wed, 9 Nov 2022 18:59:54 +0000 (9 10:59 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 9 Nov 2022 18:59:54 +0000 (9 10:59 -0800)
tree54a10a49d8347dad6521b689e79c847509555c35
parent95692e294abac5524f28368287102f6fc3d67ebf
FileRwLock separate "exclusive" from "exclusive+write"

Summary:
Previously, FileRwLock::write() would obtain an exclusive lock and poison the file at the same time.

In D40572127 (https://github.com/facebook/hhvm/commit/ff93c2382f878b226cfa269e0df93b9130f77aad), mjhostet observed "Is it expected that a write locker would usually want to change that, rather than simply locking/unlocking the file?"

He was right. It's useful to be able to obtain an exclusive lock without poisoning the file. This way, for instance, you can have one process which holds an exclusive lock but relinquishes it if someone does Ctrl+C. I use this feature extensively in the next diff in the stack.

This diff allows for flows like the following:
```
let guard = lock.exclusive()?; // obtain an exclusive lock
let guard = guard.write()?; // poison it, and start writing
*guard = 15;
let guard = guard.commit()?; // commit to disk, but retain the lock
drop(guard); // release the lock
```

Reviewed By: mjhostet

Differential Revision: D40917437

fbshipit-source-id: 4f57d4ddcce6a9f2eef41a542de8b04751cac6dd
hphp/hack/src/utils/rust/file_rwlock.rs