/* $Id$ */
/** @file
* IPRT - Spinlock, generic implementation.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** @def RT_CFG_SPINLOCK_GENERIC_DO_SLEEP
* Force cpu yields after spinning the number of times indicated by the define.
* If 0 we will spin forever. */
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/spinlock.h>
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
# include <iprt/asm-amd64-x86.h>
#endif
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Generic spinlock structure.
*/
typedef struct RTSPINLOCKINTERNAL
{
/** Spinlock magic value (RTSPINLOCK_GEN_MAGIC). */
/** The spinlock creation flags. */
/** The spinlock. */
/** The saved CPU interrupt. */
{
AssertReturn(fFlags == RTSPINLOCK_FLAGS_INTERRUPT_SAFE || fFlags == RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, VERR_INVALID_PARAMETER);
/*
* Allocate.
*/
if (!pThis)
return VERR_NO_MEMORY;
/*
* Initialize and return.
*/
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
if (!pThis)
return VERR_INVALID_PARAMETER;
{
return VERR_INVALID_PARAMETER;
}
return VINF_SUCCESS;
}
{
{
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
#endif
for (;;)
{
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
#endif
for (int c = RT_CFG_SPINLOCK_GENERIC_DO_SLEEP; c > 0; c--)
{
{
# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
# endif
return;
}
ASMNopPause();
}
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
#endif
}
#else
for (;;)
{
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
#endif
{
# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
# endif
return;
}
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
#endif
ASMNopPause();
}
#endif
}
else
{
for (;;)
{
for (int c = RT_CFG_SPINLOCK_GENERIC_DO_SLEEP; c > 0; c--)
{
return;
ASMNopPause();
}
}
#else
ASMNopPause();
#endif
}
}
{
{
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
#endif
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
#endif
}
else
{
}
}