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