-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c35831
commit b7a069d
Showing
42 changed files
with
4,290 additions
and
313 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED | ||
#define BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED | ||
|
||
// MS compatible compilers support #pragma once | ||
|
||
#if defined(_MSC_VER) && (_MSC_VER >= 1020) | ||
# pragma once | ||
#endif | ||
|
||
// boost/core/detail/sp_thread_pause.hpp | ||
// | ||
// inline void bost::core::sp_thread_pause(); | ||
// | ||
// Emits a "pause" instruction. | ||
// | ||
// Copyright 2008, 2020, 2023 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0 | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/minconfig.hpp> | ||
|
||
#if defined(__has_builtin) | ||
# if __has_builtin(__builtin_ia32_pause) && !defined(__INTEL_COMPILER) | ||
# define BOOST_CORE_HAS_BUILTIN_IA32_PAUSE | ||
# endif | ||
#endif | ||
|
||
#if defined(BOOST_CORE_HAS_BUILTIN_IA32_PAUSE) | ||
|
||
# define BOOST_CORE_SP_PAUSE() __builtin_ia32_pause() | ||
|
||
#elif defined(_MSC_VER) && ( defined(_M_IX86) || defined(_M_X64) ) | ||
|
||
# include <intrin.h> | ||
# define BOOST_CORE_SP_PAUSE() _mm_pause() | ||
|
||
#elif defined(_MSC_VER) && ( defined(_M_ARM) || defined(_M_ARM64) ) | ||
|
||
# include <intrin.h> | ||
# define BOOST_CORE_SP_PAUSE() __yield() | ||
|
||
#elif defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) ) | ||
|
||
# define BOOST_CORE_SP_PAUSE() __asm__ __volatile__( "rep; nop" : : : "memory" ) | ||
|
||
#elif defined(__GNUC__) && ( (defined(__ARM_ARCH) && __ARM_ARCH >= 8) || defined(__ARM_ARCH_8A__) || defined(__aarch64__) ) | ||
|
||
# define BOOST_CORE_SP_PAUSE() __asm__ __volatile__( "yield" : : : "memory" ) | ||
|
||
#else | ||
|
||
# define BOOST_CORE_SP_PAUSE() ((void)0) | ||
|
||
#endif | ||
|
||
namespace boost | ||
{ | ||
namespace core | ||
{ | ||
|
||
BOOST_FORCEINLINE void sp_thread_pause() noexcept | ||
{ | ||
BOOST_CORE_SP_PAUSE(); | ||
} | ||
|
||
} // namespace core | ||
} // namespace boost | ||
|
||
#undef BOOST_CORE_SP_PAUSE | ||
|
||
#endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_PAUSE_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#ifndef BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED | ||
#define BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED | ||
|
||
// MS compatible compilers support #pragma once | ||
|
||
#if defined(_MSC_VER) && (_MSC_VER >= 1020) | ||
# pragma once | ||
#endif | ||
|
||
// boost/core/detail/sp_thread_sleep.hpp | ||
// | ||
// inline void bost::core::sp_thread_sleep(); | ||
// | ||
// Cease execution for a while to yield to other threads, | ||
// as if by calling nanosleep() with an appropriate interval. | ||
// | ||
// Copyright 2008, 2020, 2023 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0 | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/minconfig.hpp> | ||
|
||
#if defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) | ||
|
||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION) | ||
BOOST_PRAGMA_MESSAGE("Using Sleep(1) in sp_thread_sleep") | ||
#endif | ||
|
||
#include <boost/core/detail/sp_win32_sleep.hpp> | ||
|
||
namespace boost | ||
{ | ||
namespace core | ||
{ | ||
namespace detail | ||
{ | ||
|
||
inline void sp_thread_sleep() noexcept | ||
{ | ||
Sleep( 1 ); | ||
} | ||
|
||
} // namespace detail | ||
|
||
using boost::core::detail::sp_thread_sleep; | ||
|
||
} // namespace core | ||
} // namespace boost | ||
|
||
#elif defined(BOOST_HAS_NANOSLEEP) | ||
|
||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION) | ||
BOOST_PRAGMA_MESSAGE("Using nanosleep() in sp_thread_sleep") | ||
#endif | ||
|
||
#include <time.h> | ||
|
||
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__) | ||
# include <pthread.h> | ||
#endif | ||
|
||
namespace boost | ||
{ | ||
namespace core | ||
{ | ||
|
||
inline void sp_thread_sleep() noexcept | ||
{ | ||
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__) | ||
|
||
int oldst; | ||
pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldst ); | ||
|
||
#endif | ||
|
||
// g++ -Wextra warns on {} or {0} | ||
struct timespec rqtp = { 0, 0 }; | ||
|
||
// POSIX says that timespec has tv_sec and tv_nsec | ||
// But it doesn't guarantee order or placement | ||
|
||
rqtp.tv_sec = 0; | ||
rqtp.tv_nsec = 1000; | ||
|
||
nanosleep( &rqtp, 0 ); | ||
|
||
#if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__) | ||
|
||
pthread_setcancelstate( oldst, &oldst ); | ||
|
||
#endif | ||
|
||
} | ||
|
||
} // namespace core | ||
} // namespace boost | ||
|
||
#else | ||
|
||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION) | ||
BOOST_PRAGMA_MESSAGE("Using sp_thread_yield() in sp_thread_sleep") | ||
#endif | ||
|
||
#include <boost/core/detail/sp_thread_yield.hpp> | ||
|
||
namespace boost | ||
{ | ||
namespace core | ||
{ | ||
|
||
inline void sp_thread_sleep() noexcept | ||
{ | ||
sp_thread_yield(); | ||
} | ||
|
||
} // namespace core | ||
} // namespace boost | ||
|
||
#endif | ||
|
||
#endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#ifndef BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED | ||
#define BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED | ||
|
||
// MS compatible compilers support #pragma once | ||
|
||
#if defined(_MSC_VER) && (_MSC_VER >= 1020) | ||
# pragma once | ||
#endif | ||
|
||
// boost/core/detail/sp_thread_yield.hpp | ||
// | ||
// inline void bost::core::sp_thread_yield(); | ||
// | ||
// Gives up the remainder of the time slice, | ||
// as if by calling sched_yield(). | ||
// | ||
// Copyright 2008, 2020 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0 | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/minconfig.hpp> | ||
|
||
#if defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) | ||
|
||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION) | ||
BOOST_PRAGMA_MESSAGE("Using SwitchToThread() in sp_thread_yield") | ||
#endif | ||
|
||
#include <boost/core/detail/sp_win32_sleep.hpp> | ||
|
||
namespace boost | ||
{ | ||
namespace core | ||
{ | ||
namespace detail | ||
{ | ||
|
||
inline void sp_thread_yield() noexcept | ||
{ | ||
SwitchToThread(); | ||
} | ||
|
||
} // namespace detail | ||
|
||
using boost::core::detail::sp_thread_yield; | ||
|
||
} // namespace core | ||
} // namespace boost | ||
|
||
#elif defined(BOOST_HAS_SCHED_YIELD) | ||
|
||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION) | ||
BOOST_PRAGMA_MESSAGE("Using sched_yield() in sp_thread_yield") | ||
#endif | ||
|
||
#ifndef _AIX | ||
# include <sched.h> | ||
#else | ||
// AIX's sched.h defines ::var which sometimes conflicts with Lambda's var | ||
extern "C" int sched_yield(void); | ||
#endif | ||
|
||
namespace boost | ||
{ | ||
namespace core | ||
{ | ||
|
||
inline void sp_thread_yield() noexcept | ||
{ | ||
sched_yield(); | ||
} | ||
|
||
} // namespace core | ||
} // namespace boost | ||
|
||
#else | ||
|
||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION) | ||
BOOST_PRAGMA_MESSAGE("Using sp_thread_pause() in sp_thread_yield") | ||
#endif | ||
|
||
#include <boost/core/detail/sp_thread_pause.hpp> | ||
|
||
namespace boost | ||
{ | ||
namespace core | ||
{ | ||
|
||
inline void sp_thread_yield() noexcept | ||
{ | ||
sp_thread_pause(); | ||
} | ||
|
||
} // namespace core | ||
} // namespace boost | ||
|
||
#endif | ||
|
||
#endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef BOOST_CORE_DETAIL_SP_WIN32_SLEEP_HPP_INCLUDED | ||
#define BOOST_CORE_DETAIL_SP_WIN32_SLEEP_HPP_INCLUDED | ||
|
||
// MS compatible compilers support #pragma once | ||
|
||
#if defined(_MSC_VER) && (_MSC_VER >= 1020) | ||
# pragma once | ||
#endif | ||
|
||
// boost/core/detail/sp_win32_sleep.hpp | ||
// | ||
// Declares the Win32 Sleep() function. | ||
// | ||
// Copyright 2008, 2020 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0 | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#if defined( BOOST_USE_WINDOWS_H ) | ||
# include <windows.h> | ||
#endif | ||
|
||
namespace boost | ||
{ | ||
namespace core | ||
{ | ||
namespace detail | ||
{ | ||
|
||
#if !defined( BOOST_USE_WINDOWS_H ) | ||
|
||
#if defined(__clang__) && defined(__x86_64__) | ||
// clang x64 warns that __stdcall is ignored | ||
# define BOOST_CORE_SP_STDCALL | ||
#else | ||
# define BOOST_CORE_SP_STDCALL __stdcall | ||
#endif | ||
|
||
#if defined(__LP64__) // Cygwin 64 | ||
extern "C" __declspec(dllimport) void BOOST_CORE_SP_STDCALL Sleep( unsigned int ms ); | ||
#else | ||
extern "C" __declspec(dllimport) void BOOST_CORE_SP_STDCALL Sleep( unsigned long ms ); | ||
#endif | ||
|
||
extern "C" __declspec(dllimport) int BOOST_CORE_SP_STDCALL SwitchToThread(); | ||
|
||
#undef BOOST_CORE_SP_STDCALL | ||
|
||
#endif // !defined( BOOST_USE_WINDOWS_H ) | ||
|
||
} // namespace detail | ||
} // namespace core | ||
} // namespace boost | ||
|
||
#endif // #ifndef BOOST_CORE_DETAIL_SP_WIN32_SLEEP_HPP_INCLUDED |
Oops, something went wrong.