mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
Beast includes a lot of code for encapsulating cross-platform differences which are not used or needed by rippled. Additionally, a lot of that code implements functionality that is available from the standard library. This moves away from custom implementations of features that the standard library provides and reduces the number of platform-specific interfaces andfeatures that Beast makes available. Highlights include: * Use std:: instead of beast implementations when possible * Reduce the use of beast::String in public interfaces * Remove Windows-specific COM and Registry code * Reduce the public interface of beast::File * Reduce the public interface of beast::SystemStats * Remove unused sysctl/getsysinfo functions * Remove beast::Logger
104 lines
4.2 KiB
C++
104 lines
4.2 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
|
|
Portions of this file are from JUCE.
|
|
Copyright (c) 2013 - Raw Material Software Ltd.
|
|
Please visit http://www.juce.com
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
namespace beast
|
|
{
|
|
|
|
void* getUser32Function (const char* functionName)
|
|
{
|
|
HMODULE module = GetModuleHandleA ("user32.dll");
|
|
bassert (module != 0);
|
|
return (void*) GetProcAddress (module, functionName);
|
|
}
|
|
|
|
//==============================================================================
|
|
#if ! BEAST_USE_INTRINSICS
|
|
// In newer compilers, the inline versions of these are used (in beast_Atomic.h), but in
|
|
// older ones we have to actually call the ops as win32 functions..
|
|
long beast_InterlockedExchange (volatile long* a, long b) noexcept { return InterlockedExchange (a, b); }
|
|
long beast_InterlockedIncrement (volatile long* a) noexcept { return InterlockedIncrement (a); }
|
|
long beast_InterlockedDecrement (volatile long* a) noexcept { return InterlockedDecrement (a); }
|
|
long beast_InterlockedExchangeAdd (volatile long* a, long b) noexcept { return InterlockedExchangeAdd (a, b); }
|
|
long beast_InterlockedCompareExchange (volatile long* a, long b, long c) noexcept { return InterlockedCompareExchange (a, b, c); }
|
|
|
|
__int64 beast_InterlockedCompareExchange64 (volatile __int64* value, __int64 newValue, __int64 valueToCompare) noexcept
|
|
{
|
|
bassertfalse; // This operation isn't available in old MS compiler versions!
|
|
|
|
__int64 oldValue = *value;
|
|
if (oldValue == valueToCompare)
|
|
*value = newValue;
|
|
|
|
return oldValue;
|
|
}
|
|
|
|
#endif
|
|
|
|
//==============================================================================
|
|
|
|
|
|
CriticalSection::CriticalSection() noexcept
|
|
{
|
|
// (just to check the MS haven't changed this structure and broken things...)
|
|
#if BEAST_VC7_OR_EARLIER
|
|
static_assert (sizeof (CRITICAL_SECTION) <= 24,
|
|
"The size of the CRITICAL_SECTION structure is less not what we expected.");
|
|
#else
|
|
static_assert (sizeof (CRITICAL_SECTION) <= sizeof (CriticalSection::section),
|
|
"The size of the CRITICAL_SECTION structure is less not what we expected.");
|
|
#endif
|
|
|
|
InitializeCriticalSection ((CRITICAL_SECTION*) section);
|
|
}
|
|
|
|
CriticalSection::~CriticalSection() noexcept { DeleteCriticalSection ((CRITICAL_SECTION*) section); }
|
|
void CriticalSection::enter() const noexcept { EnterCriticalSection ((CRITICAL_SECTION*) section); }
|
|
bool CriticalSection::tryEnter() const noexcept { return TryEnterCriticalSection ((CRITICAL_SECTION*) section) != FALSE; }
|
|
void CriticalSection::exit() const noexcept { LeaveCriticalSection ((CRITICAL_SECTION*) section); }
|
|
|
|
//==============================================================================
|
|
bool beast_isRunningUnderDebugger()
|
|
{
|
|
return IsDebuggerPresent() != FALSE;
|
|
}
|
|
|
|
bool Process::isRunningUnderDebugger()
|
|
{
|
|
return beast_isRunningUnderDebugger();
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
void Process::terminate()
|
|
{
|
|
#if BEAST_MSVC && BEAST_CHECK_MEMORY_LEAKS
|
|
_CrtDumpMemoryLeaks();
|
|
#endif
|
|
|
|
// bullet in the head in case there's a problem shutting down..
|
|
ExitProcess (0);
|
|
}
|
|
|
|
//==============================================================================
|
|
|
|
} // beast
|