The original code was 100% correct. It is the model that we use
through out the code, and it is the model that we should continue
to use. It allows people to do
UNLOCK(mutex);
which is what most programmers expect.
Ryan
On Wednesday 05 December 2001 08:44 am, Brian Pane wrote:
> Aaron Bannert wrote:
> >On Wed, Dec 05, 2001 at 12:35:00PM +0100, Sander Striker wrote:
> >>><comment>
> >>>Ack. No. Declare a new scope like so:
> >>>#define UNLOCK(mutex) \
> >>> do { \
> >>> if (mutex) \
> >>> apr_thread_mutex_unlock(mutex); \
> >>> } while(0)
> >>>
> >>>Calling it like UNLOCK(mutex) (i.e. no semicolon) is just badness
> >>>and will shoot us down the road later.
> >>></comment>
> >>
> >>Ok, will change that.
> >
> >If the semicolon is the only problem, just remove the semicolon from
> >the macro:
> >
> >#define UNLOCK(mutex) \
> > if (mutex) \
> > apr_thread_mutex_unlock(mutex)
>
> I recommend still creating a scope around the if-statement:
> #define UNLOCK(mutex) \
> { \
> if (mutex) \
> apr_thread_mutex_unlock(mutex); \
> }
>
> That will guard against unintended effects when the macro
> is used in code like this:
>
> if (condition)
> UNLOCK(mutex)
> else
> ...
>
> --Brian
--
______________________________________________________________
Ryan Bloom [EMAIL PROTECTED]
Covalent Technologies [EMAIL PROTECTED]
--------------------------------------------------------------