Date: Wed, 20 Sep 1995 16:58:44 -0500 (CDT) From: Mike Pritchard <mpp@mpp.minn.net> To: terry@lambert.org (Terry Lambert) Cc: terry@lambert.org, nate@rocky.sri.MT.net, davidg@root.com, hackers@freefall.freebsd.org Subject: Re: Coding style ( was Re: why is this not a bug in namei?) Message-ID: <199509202158.QAA12896@mpp.minn.net> In-Reply-To: <199509201711.KAA01075@phaeton.artisoft.com> from "Terry Lambert" at Sep 20, 95 10:11:52 am
next in thread | previous in thread | raw e-mail | index | archive | help
Terry Lambert wrote: > > Why not: > > XXX_LOCK(); > ... > if (error_condition) { > error = EWHATEVER; > goto err_with_lock_held; > } > ... > err_with_lock_held: > XXX_UNLOCK(): > err: > return (error); > > Or better yet: > > XXX_LOCK(); > ... > if (error_condition) { > error = EWHATEVER; > } else { > ... > } > XXX_UNLOCK(): > err: > return (error); > > I don't understand the need for the local lock state variable in your > second example. My previous example was very simplistic. Having to lock multiple objects during a function wasn't not uncommon. E.g. XXX_LOCK(); ... if (error_condition) { XXX_UNLOCK(); return (EWHATEVER); } ... XXX_UNLOCK(); ... if (error_condition2) return (EHWATEVER); ... YYY_LOCK(); ... if (error_condition2) { YYY_UNLOCK(); return (EWHATEVER); } ... YYY_UNLOCK(); return (0); In the above example, with gotos you would need 4 exit points: 1 for an exit without any error. And one each for each of the 3 error conditions, since they all have different requirements. 2 of them have different locks, and 1 has no locks at all. -- Mike Pritchard mpp@mpp.minn.net "Go that way. Really fast. If something gets in your way, turn"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199509202158.QAA12896>