jonhoo / guardian

Owned mutex guards for refcounted mutexes.
Apache License 2.0
14 stars 4 forks source link

try_take #6

Closed marvin-j97 closed 1 month ago

marvin-j97 commented 2 months ago

Is it possible for guardian to implement something like Mutex::try_lock (try_take?), that doesn't block the thread if it can't take the mutex immediately? I have a situation where I have multiple mutexes that may or may not be blocked, and I want to iterate through them to find an open lock. With guardian that is currently not possible, but it would be nice to get the lifetime-free lock guard.

jonhoo commented 2 months ago

Hmm, yes, I think that should be doable! You'd just want a variant of

https://github.com/jonhoo/guardian/blob/2460e843a5557df4def9ae8b20a4f3700bd84cce/src/lib.rs#L216

That calls try_lock and returns an Option. I'm a bit short on time at the moment, but would be happy to review a PR!

marvin-j97 commented 2 months ago

https://github.com/jonhoo/guardian/pull/7