CMCore/inc/hgl/thread/Atomic.h
2019-08-19 19:19:58 +08:00

62 lines
2.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef HGL_ATOMIC_INCLUDE
#define HGL_ATOMIC_INCLUDE
#include<hgl/platform/Platform.h>
#if HGL_OS == HGL_OS_Windows
#include<hgl/thread/atomic/AtomicWin.h>
#elif (HGL_OS == HGL_OS_macOS)||(HGL_OS == HGL_OS_Android)
#include<atomic>
template<typename T> using atom=std::atomic<T>;
#elif defined(__GNUC__)
#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) && (defined(__x86_64__) || defined(__i386__) || defined(__powerpc__))
#include<hgl/thread/atomic/AtomicGNU.h>
#else
#include<hgl/thread/atomic/AtomicAPR.h>
#endif//
#endif//
//ps.1老旧的Linux/32bit下原子仅支持24位但我们设定为不支持旧的Linux
//ps.2使用GCC 4.1内置宏实现的AtomicGNU的不支持doubel型处理如需支持则尽可能不要用atom_double
//ps..........GCC4.7/4.8/4.9下如果使用c++11的atomic会造成一些valgrind-memcheck报错所以暂不使用。待valgrind更新
namespace hgl
{
#if (HGL_OS == HGL_OS_Windows)//&&(!defined(HGL_ATOMIC_CPP11))
typedef atom_win32<int > atom_int;
typedef atom_win32<uint > atom_uint;
typedef atom_win32<int32 > atom_int32;
typedef atom_win32<uint32 > atom_uint32;
typedef atom_win64<int64 > atom_int64;
typedef atom_win64<uint64 > atom_uint64;
typedef atom_win32<float > atom_float;
// typedef atom_win64<double > atom_double;
typedef atom_win32<bool > atom_bool;
typedef atom_win32<char > atom_char;
typedef atom_win32<uchar > atom_uchar;
// typedef atom_win32<wchar_t > atom_wchar;
typedef atom_win32<u16char > atom_char16;
// typedef atom_win32<char32_t > atom_char32;
#else
typedef atom<bool > atom_bool;
typedef atom<int > atom_int;
typedef atom<uint > atom_uint;
typedef atom<int32 > atom_int32;
typedef atom<uint32 > atom_uint32;
typedef atom<int64 > atom_int64;
typedef atom<uint64 > atom_uint64;
typedef atom<float > atom_float;
// typedef atom<double > atom_double;
typedef atom<char > atom_char;
typedef atom<uchar > atom_uchar;
// typedef atom<wchar_t > atom_wchar;
typedef atom<u16char > atom_char16;
// typedef atom<char32_t > atom_char32;
#endif//windows & !c++11
}//namespace hgl
#endif//HGL_ATOMIC_INCLUDE