apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ryan Bloom <...@covalent.net>
Subject Re: Pools rewrite [2]
Date Wed, 05 Dec 2001 17:01:53 GMT

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				rbb@apache.org
Covalent Technologies			rbb@covalent.net
--------------------------------------------------------------

Mime
View raw message