Re: rwlock(9) and mutex(9) definitions
- In reply to: Gleb Smirnoff : "rwlock(9) and mutex(9) definitions"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 27 Oct 2021 08:24:50 UTC
-------- Gleb Smirnoff writes: > Such wraps don't really behave as a true void. For example you > can not tail call them: > > void > smartass_lock(lock, clue) > { > if (clue) > return (rw_rlock(lock)); > else > return (rw_wlock(lock)); > } > > This will fail on rw_wlock, but not on rw_rlock. However, if you > have WITNESS it will compile correctly :) I'm not going to go full Bruce on you here, but... In your example above, at the very least the "else" is surplus to requirements. The "return" around rw_wlock also doesnt do nothing for its keep. That leaves us with: void smartass_lock(lock, clue) { if (clue) return (rw_rlock(lock)); rw_wlock(lock); } That has pretty low aesthetic qualities, which is why I myself would have written it as: void smartass_lock(lock, clue) { if (clue) rw_rlock(lock); else rw_wlock(lock); } Finally "return(something_void)" is bad style in my book, because "void" literally means there is no return value to begin with. So all in all, I fail to see a problem that needs fixing ? I realize that the above may be a simplified example of the real problem you're trying to solve, but if so, it is too simplified to carry your argument. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.