2 ms·
We have a nice macro for acquiring locks that only applies to the scope: https://github.com/libguestfs/nbdkit/blob/e58d28d65bfea3af3694502c4030838f3cf5d6e8/com
by rwmj 7y ago
We have a nice macro for acquiring locks that only applies to the scope:
https://github.com/libguestfs/nbdkit/blob/e58d28d65bfea3af3694502c4030838f3cf5d6e8/common/utils/cleanup.h#L44 https://github.com/libguestfs/nbdkit/blob/e58d28d65bfea3af36...
You end up with code like this:
https://github.com/libguestfs/nbdkit/blob/e58d28d65bfea3af3694502c4030838f3cf5d6e8/server/protocol.c#L369 https://github.com/libguestfs/nbdkit/blob/e58d28d65bfea3af36...
It's so useful to be able to be sure the lock is released on all return paths. Also because it's scope-level you can scope your locks tightly to where they are needed.