Skip to content

Commit

Permalink
Merge pull request #3 from RA-Kooi/DefineSoup
Browse files Browse the repository at this point in the history
Use EABase defines over raw platform checks
  • Loading branch information
rparolin authored Mar 3, 2020
2 parents e4367a3 + e208999 commit b05f3b3
Show file tree
Hide file tree
Showing 49 changed files with 223 additions and 366 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ add_library(EAThread ${EATHREAD_SOURCES})

if(EATHREAD_BUILD_TESTS)
add_subdirectory(test)
else()
add_subdirectory(test/packages/EABase)
endif()

#-------------------------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions include/eathread/eathread.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
EA_RESTORE_VC_WARNING()
#elif defined(EA_PLATFORM_UNIX) || EA_POSIX_THREADS_AVAILABLE
#include <pthread.h>
#if defined(_YVALS) // Dinkumware doesn't usually provide gettimeofday or <sys/types.h>
#if defined(EA_HAVE_DINKUMWARE_CPP_LIBRARY) // Dinkumware doesn't usually provide gettimeofday or <sys/types.h>
#include <time.h> // clock_gettime
#elif defined(EA_PLATFORM_UNIX)
#include <sys/time.h> // gettimeofday
Expand Down Expand Up @@ -728,7 +728,7 @@ namespace EA
#if EA_USE_CPP11_CONCURRENCY
#define EAThreadGetUniqueId(dest) (dest = static_cast<uintptr_t>(std::hash<std::thread::id>()(std::this_thread::get_id())))

#elif defined(EA_PLATFORM_WINDOWS) && defined(_MSC_VER) && !defined(_WIN64)
#elif defined(EA_PLATFORM_WINDOWS) && defined(EA_COMPILER_MSVC) && !defined(EA_PLATFORM_WIN64)

// Reference implementation:
//extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
Expand All @@ -739,10 +739,10 @@ namespace EA
#pragma intrinsic(__readfsdword)
#define EAThreadGetUniqueId(dest) dest = (EA::Thread::ThreadUniqueId)(uintptr_t)__readfsdword(0x18)

#elif defined(_MSC_VER) && defined(EA_PROCESSOR_X86_64)
#pragma warning(push, 0)
#elif defined(EA_COMPILER_MSVC) && defined(EA_PROCESSOR_X86_64)
EA_DISABLE_ALL_VC_WARNINGS()
#include <intrin.h>
#pragma warning(pop)
EA_RESTORE_ALL_VC_WARNINGS()
#define EAThreadGetUniqueId(dest) dest = (EA::Thread::ThreadUniqueId)(uintptr_t)__readgsqword(0x30)
// Could also use dest = (EA::Thread::ThreadUniqueId)NtCurrentTeb(), but that would require #including <windows.h>, which is very heavy.

Expand Down
11 changes: 4 additions & 7 deletions include/eathread/eathread_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,9 @@ namespace EA
#endif


#ifdef _MSC_VER // VC++ yields spurious warnings about void* being cast to an integer type and vice-versa.
#pragma warning(push) // These warnings are baseless because we check for platform pointer size above.
#pragma warning(disable: 4311 4312 4251)
#endif
// VC++ yields spurious warnings about void* being cast to an integer type and vice-versa.
// These warnings are baseless because we check for platform pointer size above.
EA_DISABLE_VC_WARNING(4311 4312 4251)


/// class AtomicPointer
Expand Down Expand Up @@ -455,9 +454,7 @@ namespace EA
};


#ifdef _MSC_VER
#pragma warning(pop)
#endif
EA_RESTORE_VC_WARNING()

} // namespace Thread

Expand Down
11 changes: 5 additions & 6 deletions include/eathread/eathread_barrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
#include <eathread/eathread.h>


#if defined(EA_DLL) && defined(_MSC_VER)
#if defined(EA_DLL) && defined(EA_COMPILER_MSVC)
// Suppress warning about class 'AtomicInt32' needs to have a
// dll-interface to be used by clients of class which have a templated member.
//
// These templates cannot be instantiated outside of the DLL. If you try, a
// link error will result. This compiler warning is intended to notify users
// of this.
#pragma warning(push)
#pragma warning(disable: 4251)
EA_DISABLE_VC_WARNING(4251)
#endif

#if defined(EA_PRAGMA_ONCE_SUPPORTED)
Expand Down Expand Up @@ -227,9 +226,9 @@ namespace EA
} // namespace EA


#if defined(EA_DLL) && defined(_MSC_VER)
// re-enable warning(s) disabled above.
#pragma warning(pop)
#if defined(EA_DLL) && defined(EA_COMPILER_MSVC)
// re-enable warning(s) disabled above.
EA_RESTORE_VC_WARNING()
#endif


Expand Down
16 changes: 8 additions & 8 deletions include/eathread/eathread_callstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace EA
/// void* pInstruction;
/// EAGetInstructionPointer(pInstruction);
///
#if defined(_MSC_VER) && defined(EA_PROCESSOR_X86)
#if defined(EA_COMPILER_MSVC) && defined(EA_PROCESSOR_X86)
// We implement this via calling the next line of code as a function.
// Then we continue as if we were exiting that function but with no
// return statement. The result is that the instruction pointer will
Expand All @@ -204,13 +204,13 @@ namespace EA
{EAGetInstructionPointer(p);}
EA_RESTORE_VC_WARNING()

#elif defined(_MSC_VER) && (defined(EA_PROCESSOR_X86_64) || defined(EA_PROCESSOR_ARM))
#elif defined(EA_COMPILER_MSVC) && (defined(EA_PROCESSOR_X86_64) || defined(EA_PROCESSOR_ARM))

EATHREADLIB_API EA_NO_INLINE void GetInstructionPointer(void*& p);

#define EAGetInstructionPointer(p) EA::Thread::GetInstructionPointer(p)

#elif defined(__ARMCC_VERSION) // ARM compiler
#elif defined(EA_COMPILER_ARM) // ARM compiler

// Even if there are compiler intrinsics that let you get the instruction pointer,
// this function can still be useful. For example, on ARM platforms this function
Expand All @@ -226,7 +226,7 @@ namespace EA
// // To do: implement this directly instead of via a call to GetInstructionPointer.
// #define EAGetInstructionPointer(p) EA::Thread::GetInstructionPointer(p)

#elif defined(__GNUC__) || defined(EA_COMPILER_CLANG) // This covers EA_PLATFORM_UNIX, EA_PLATFORM_OSX
#elif defined(EA_COMPILER_GNUC) || defined(EA_COMPILER_CLANG) // This covers EA_PLATFORM_UNIX, EA_PLATFORM_OSX

// Even if there are compiler intrinsics that let you get the instruction pointer,
// this function can still be useful. For example, on ARM platforms this function
Expand Down Expand Up @@ -289,27 +289,27 @@ namespace EA
EATHREADLIB_API void* GetStackLimit();


#if defined(_MSC_VER) && defined(EA_PROCESSOR_X86)
#if defined(EA_COMPILER_MSVC) && defined(EA_PROCESSOR_X86)
#define EASetStackBase() \
{ \
void* esp; \
__asm { mov esp, ESP } \
::EA::Thread::SetStackBase(esp); \
}

#elif defined(_MSC_VER) && (defined(EA_PROCESSOR_X86_64) || defined(EA_PROCESSOR_ARM))
#elif defined(EA_COMPILER_MSVC) && (defined(EA_PROCESSOR_X86_64) || defined(EA_PROCESSOR_ARM))
// This implementation uses SetStackBase(NULL), which internally retrieves the stack pointer.
#define EASetStackBase() \
{ \
::EA::Thread::SetStackBase((void*)NULL); \
} \

#elif defined(__ARMCC_VERSION) // ARM compiler
#elif defined(EA_COMPILER_ARM) // ARM compiler

#define EASetStackBase() \
::EA::Thread::SetStackBase((void*)__current_sp())

#elif defined(__GNUC__) // This covers EA_PLATFORM_UNIX, EA_PLATFORM_OSX
#elif defined(EA_COMPILER_GNUC) // This covers EA_PLATFORM_UNIX, EA_PLATFORM_OSX

#define EASetStackBase() \
::EA::Thread::SetStackBase((void*)__builtin_frame_address(0));
Expand Down
19 changes: 4 additions & 15 deletions include/eathread/eathread_condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
#include <eathread/eathread_mutex.h>


#if defined(EA_DLL) && defined(_MSC_VER)
#if defined(EA_DLL) && defined(EA_COMPILER_MSVC)
// Suppress warning about class 'EA::Thread::simple_list<T>' needs to have
// dll-interface to be used by clients of class which have a templated member.
//
// These templates cannot be instantiated outside of the DLL. If you try, a
// link error will result. This compiler warning is intended to notify users
// of this.
#pragma warning(push)
#pragma warning(disable: 4251)
EA_DISABLE_VC_WARNING(4251)
#endif

#if defined(EA_PRAGMA_ONCE_SUPPORTED)
Expand Down Expand Up @@ -234,21 +233,11 @@ namespace EA



#if defined(EA_DLL) && defined(_MSC_VER)
#if defined(EA_DLL) && defined(EA_COMPILER_MSVC)
// re-enable warning 4251 (it's a level-1 warning and should not be suppressed globally)
#pragma warning(pop)
EA_RESTORE_VC_WARNING()
#endif



#endif // EATHREAD_EATHREAD_CONDITION_H










14 changes: 7 additions & 7 deletions include/eathread/eathread_futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
#include <mutex>
EA_RESTORE_VC_WARNING()

#elif defined(__APPLE__)
#elif defined(EA_PLATFORM_APPLE)
#if EATHREAD_MANUAL_FUTEX_ENABLED
#include <eathread/eathread_semaphore.h>
typedef EA::Thread::Semaphore EAFutexSemaphore;
Expand Down Expand Up @@ -149,9 +149,9 @@ namespace EA
{
namespace Thread
{
#if defined(_WIN64)
#if defined(EA_PLATFORM_WIN64)
static const int FUTEX_PLATFORM_DATA_SIZE = 40; // CRITICAL_SECTION is 40 bytes on Win64.
#elif defined(_WIN32)
#elif defined(EA_PLATFORM_WIN32)
static const int FUTEX_PLATFORM_DATA_SIZE = 32; // CRITICAL_SECTION is 24 bytes on Win32 and 28 bytes on XBox 360.
#endif

Expand Down Expand Up @@ -288,7 +288,7 @@ namespace EA
#elif defined(EA_COMPILER_MSVC) && defined(EA_PLATFORM_MICROSOFT) // In the case of Microsoft platforms, we just use CRITICAL_SECTION, as it is essentially a futex.
// We use raw structure math because otherwise we'd expose the user to system headers,
// which breaks code and bloats builds. We validate our math in eathread_futex.cpp.
#if defined(_WIN64)
#if defined(EA_PLATFORM_WIN64)
uint64_t mCRITICAL_SECTION[FUTEX_PLATFORM_DATA_SIZE / sizeof(uint64_t)];
#else
uint64_t mCRITICAL_SECTION[FUTEX_PLATFORM_DATA_SIZE / sizeof(uint64_t)];
Expand Down Expand Up @@ -704,7 +704,7 @@ namespace EA

// We use raw structure math because otherwise we'd expose the user to system headers,
// which breaks code and bloats builds. We validate our math in eathread_futex.cpp.
#if defined(_WIN64)
#if defined(EA_PLATFORM_WIN64)
return *((int*)mCRITICAL_SECTION + 3);
#else
return *((int*)mCRITICAL_SECTION + 2);
Expand All @@ -717,7 +717,7 @@ namespace EA

// We use raw structure math because otherwise we'd expose the user to system headers,
// which breaks code and bloats builds. We validate our math in eathread_futex.cpp.
#if defined(_WIN64)
#if defined(EA_PLATFORM_WIN64)
return (*((uint32_t*)mCRITICAL_SECTION + 4) == (uintptr_t)GetCurrentThreadId());
#else
return (*((uint32_t*)mCRITICAL_SECTION + 3) == (uintptr_t)GetCurrentThreadId());
Expand Down Expand Up @@ -758,7 +758,7 @@ namespace EA
inline void Futex::SetSpinCount(Uint)
{ }

#endif // _MSC_VER
#endif // EA_COMPILER_MSVC

#endif // EATHREAD_MANUAL_FUTEX_ENABLED

Expand Down
2 changes: 1 addition & 1 deletion include/eathread/eathread_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef EATHREAD_EATHREAD_MUTEX_H
#define EATHREAD_EATHREAD_MUTEX_H

#if defined(_MSC_VER)
#if defined(EA_COMPILER_MSVC)
#include <math.h> // #include math.h because VC++ has a header file but that requires math.h to be #included before some other headers, lest you get a warning.
#endif
#include <stddef.h>
Expand Down
9 changes: 4 additions & 5 deletions include/eathread/eathread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
#include <stddef.h>


#if defined(EA_DLL) && defined(_MSC_VER)
#if defined(EA_DLL) && defined(EA_COMPILER_MSVC)
// Suppress warning about class 'EA::Thread::simple_list<T>' needs to have
// dll-interface to be used by clients of class which have a templated member.
//
// These templates cannot be instantiated outside of the DLL. If you try, a
// link error will result. This compiler warning is intended to notify users
// of this.
#pragma warning(push)
#pragma warning(disable: 4251)
EA_DISABLE_VC_WARNING(4251)
#endif

#if defined(EA_PRAGMA_ONCE_SUPPORTED)
Expand Down Expand Up @@ -282,9 +281,9 @@ namespace EA



#if defined(EA_DLL) && defined(_MSC_VER)
#if defined(EA_DLL) && defined(EA_COMPILER_MSVC)
// re-enable warning 4251 (it's a level-1 warning and should not be suppressed globally)
#pragma warning(pop)
EA_RESTORE_VC_WARNING()
#endif


Expand Down
29 changes: 7 additions & 22 deletions include/eathread/eathread_rwmutex_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@
#include <eathread/eathread.h>
#include <new>
#if EA_WINAPI_FAMILY_PARTITION(EA_WINAPI_PARTITION_DESKTOP)
#pragma warning(push, 0)
EA_DISABLE_ALL_VC_WARNINGS()
#include <Windows.h>
#pragma warning(pop)
EA_RESTORE_ALL_VC_WARNINGS()
#endif

#if defined(EA_PRAGMA_ONCE_SUPPORTED)
#pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result.
#endif


#ifdef _MSC_VER
#pragma warning(push) // We have to be careful about disabling this warning. Sometimes the warning is meaningful; sometimes it isn't.
#pragma warning(disable: 4251) // class (some template) needs to have dll-interface to be used by clients.
#pragma warning(disable: 6054) // String 'argument 2' might not be zero-terminated
#endif

// We have to be careful about disabling this warning. Sometimes the warning is meaningful; sometimes it isn't.
// 4251: class (some template) needs to have dll-interface to be used by clients.
// 6054: String 'argument 2' might not be zero-terminated
EA_DISABLE_VC_WARNING(4251 6054)

namespace EA
{
Expand Down Expand Up @@ -413,18 +410,6 @@ namespace EA

} // namespace EA



#ifdef _MSC_VER
#pragma warning(pop)
#endif

EA_RESTORE_VC_WARNING()

#endif // EATHREAD_EATHREAD_RWMUTEX_IP_H







19 changes: 2 additions & 17 deletions include/eathread/eathread_rwspinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include <eathread/eathread_atomic.h>
#include <new>


#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4100) // (Compiler claims pRWSpinLock is unreferenced)
#endif
EA_DISABLE_VC_WARNING(4100) // (Compiler claims pRWSpinLock is unreferenced)

#if defined(EA_PRAGMA_ONCE_SUPPORTED)
#pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result.
Expand Down Expand Up @@ -392,17 +388,6 @@ namespace EA

} // namespace EA



#ifdef _MSC_VER
#pragma warning(pop)
#endif

EA_RESTORE_VC_WARNING()

#endif // EATHREAD_EATHREAD_RWSPINLOCK_H






Loading

0 comments on commit b05f3b3

Please sign in to comment.