Description
#2170 deprecated flock
and replaced it with a Flock
struct, allowing for automatic unlock-on-drop behaviour. So far, so good, but I think there are several ways in which flock
can be used that cannot be modelled with this replacement. For example, upgrading or downgrading locks.
Suppose I have a shared lock and I want to upgrade it to an exclusive lock. With flock
, if there's any error, e.g. EWOULDBLOCK
/EAGAIN
(same thing), I typically would not lose the existing shared lock.
However, using Flock
, I cannot call Flock::lock
with the Flock
itself, so I would have to call Flock::unlock
first to return the enclosed Flockable
, before then calling Flock::lock
. An error in that last step would leave me with no lock.
Some ideas for how to resolve this:
- Remove the deprecation of
flock
. - Add a
Flock::relock
method that allows for upgrading/downgrading locks. - Add an
impl Flockable for Flock<T>
so that one can callFlock::lock
with aFlock
.