/************************************************************
The contents of this file are subject to the Pumpkin Salvo
License (the "License").  You may not use this file except
in compliance with the License. You may obtain a copy of
the License at http://www.pumpkininc.com, or from
warranty@pumpkininc.com.

Software distributed under the License is distributed on an
"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
or implied. See the License for specific language governing
the warranty and the rights and limitations under the
License.

The Original Code is Salvo - The RTOS that runs in tiny
places(TM). Copyright (C) 1995-2006 Pumpkin, Inc. and its
Licensor(s). All Rights Reserved.

$Source: C:\\RCS\\D\\Pumpkin\\Salvo\\inc\\salvocri.h,v $
$Author: aek $
$Revision: 3.4 $
$Date: 2006-03-22 19:38:04-08 $

Salvo critical-section macros.

************************************************************/

/************************************************************
****                                                     ****
**                                                         **
OSEnter|LeaveCritical():
OSBegin|EndCriticalSection():
OSSuspend|ResumeCriticalSection():

Macros for entering and exiting critical regions of code.

OSBegin|EndCriticalSection() are essentially placeholders
for OSEnter|LeaveCritical(), and are sometimes redefined
in the various modules to support special interrupt-related
issues.

Compilers that support the monitor keyword use the
OSMONITOR_KEYWORD_PRE symbol as an extended keyword on each
function that needs interrupts disabled, and therefore do
not need OSBegin|EndCriticalSection() macros inside the
function.

OSSuspend|ResumeCriticalSection() are special interrupt-
enabling and disabling macros, respectively, to be used
inside large functions where interrupts should not be
disabled for the duration.

**                                                         **
****                                                     ****
************************************************************/
/* Defaults for OSEnable|Disable() can be the user		*/
/*  hooks in many applications.							*/
#if !defined(OSDisable)
#define OSDisable()                     OSDisableHook()
#endif
#if !defined(OSEnable)
#define OSEnable()                     	OSEnableHook()
#endif


/* OSEnterCritical() saves existing interrupt-enable	*/
/*  status on entry via OSSaveHook(), then disables		*/
/*  selected interrupts. All Salvo services with 		*/
/*  critical sections begin the critical section with	*/
/*  OSEnterCritical().									*/
/* OSLeaveCritical() restores previous interrupt-enable */
/*  status.	All Salvo services with critical sections	*/
/*  end the critical section with OSLeaveCritical().	*/
#if !defined(OSEnterCritical)
#define OSEnterCritical()          		do \
                                     	{ \
                                     	  OSSaveHook(); \
                                     	  OSDisableHook(); \
                                     	} while (0);
#endif                                     	

#if !defined(OSLeaveCritical)
#define OSLeaveCritical()          		do \
										{ \
                                          OSRestoreHook(); \
                                        } while (0);
#endif


/* OSSuspendCriticalSection() blindly re-enables 		*/
/*  interrupts to ensure that interrupts can "creep in"	*/
/*  during long critical sections when appropriate. It  */
/*  is used only in a few Salvo services (OSSched()).	*/
/* OSResumeCriticalSection() blindly disables interrupts*/
/*  so that a critical section can continue. It always	*/
/*  follows OSSuspendCriticalSection().					*/
#if !defined(OSSuspendCriticalSection)
#define OSSuspendCriticalSection() 		do \
										{ \
                                          OSEnableHook(); \
                                   		} while (0);
#endif                                   		

#if !defined(OSResumeCriticalSection)
#define OSResumeCriticalSection()  		do \
										{ \
										  OSDisableHook(); \
                                   		} while(0);
#endif                                   		




/* These are primarily left over from Salvo v3.			*/

#if OSMONITOR_KEYWORD_EXISTS
#define OSBeginCriticalSection()
#define OSEndCriticalSection()
#else
#define OSBeginCriticalSection()        OSEnterCritical()
#define OSEndCriticalSection()          OSLeaveCritical()
#endif


#if !defined(OSResumeCriticalSection)
#define OSResumeCriticalSection()       OSEnterCritical()
#endif

#if !defined(OSSuspendCriticalSection)
#define OSSuspendCriticalSection()      OSLeaveCritical()
#endif
