/*****************************************************************************
 * $LastChangedDate: 2010-02-27 16:02:48 -0500 (Sat, 27 Feb 2010) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Macros to create a run-once block of code.
 *//*
 * LEGAL:   COPYRIGHT (C) 2007 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef BASE_BUSY_HH
#define BASE_BUSY_HH 1

#include "base/auto_flag.hh"

namespace base {

////////////////////////////////////////////////////////////////////////////////
// Macros to create a run-once block of code.
//
// Write curly braces:
// BUSY_BEGIN {
// } BUSY_END
//
// This forms an if block with an object to auto-clear the busy flag.
//
#define BUSY_BEGIN         { PERSISTENT bool sBusy = false; \
                             if ( EX( not sBusy ) )         \
                             { AutoFlag autoFlag( &sBusy );

#define BUSY_BEGIN_ASSERT  { PERSISTENT bool sBusy = false; \
                             ASSERT( not sBusy );           \
                             if ( EX( not sBusy ) )         \
                             { AutoFlag autoFlag( &sBusy );

#define BUSY_END             } /* close "if" block */       \
                           }   /* close outer block */

} // namespace base

#endif // BASE_BUSY_HH
