From b73941c0eafd74f19335e168a289a32fb57669cc Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 29 Mar 2013 07:29:31 -0700 Subject: [PATCH 1/7] Use libc++ for Mac OS X builds now that we require >= 10.7 anyway --- Source/Core/Common/Src/StdConditionVariable.h | 153 -------- Source/Core/Common/Src/StdMutex.h | 358 ------------------ Source/Core/Common/Src/StdThread.h | 310 --------------- 3 files changed, 821 deletions(-) delete mode 100644 Source/Core/Common/Src/StdConditionVariable.h delete mode 100644 Source/Core/Common/Src/StdMutex.h delete mode 100644 Source/Core/Common/Src/StdThread.h diff --git a/Source/Core/Common/Src/StdConditionVariable.h b/Source/Core/Common/Src/StdConditionVariable.h deleted file mode 100644 index 6530712c8f..0000000000 --- a/Source/Core/Common/Src/StdConditionVariable.h +++ /dev/null @@ -1,153 +0,0 @@ - -#ifndef CONDITION_VARIABLE_H_ -#define CONDITION_VARIABLE_H_ - -#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) -#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) - -#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !ANDROID -// GCC 4.4 provides -#include -#else - -// partial std::condition_variable implementation for win32/pthread - -#include "StdMutex.h" - -#if (_MSC_VER >= 1600) || (GCC_VERSION >= GCC_VER(4,3,0) && __GXX_EXPERIMENTAL_CXX0X__) -#define USE_RVALUE_REFERENCES -#endif - -#if defined(_WIN32) && defined(_M_X64) -#define USE_CONDITION_VARIABLES -#elif defined(_WIN32) -#define USE_EVENTS -#endif - -namespace std -{ - -class condition_variable -{ -#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES) - typedef CONDITION_VARIABLE native_type; -#elif defined(_WIN32) - typedef HANDLE native_type; -#else - typedef pthread_cond_t native_type; -#endif - -public: - -#ifdef USE_EVENTS - typedef native_type native_handle_type; -#else - typedef native_type* native_handle_type; -#endif - - condition_variable() - { -#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES) - InitializeConditionVariable(&m_handle); -#elif defined(_WIN32) - m_handle = CreateEvent(NULL, false, false, NULL); -#else - pthread_cond_init(&m_handle, NULL); -#endif - } - - ~condition_variable() - { -#if defined(_WIN32) && !defined(USE_CONDITION_VARIABLES) - CloseHandle(m_handle); -#elif !defined(_WIN32) - pthread_cond_destroy(&m_handle); -#endif - } - - condition_variable(const condition_variable&) /*= delete*/; - condition_variable& operator=(const condition_variable&) /*= delete*/; - - void notify_one() - { -#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES) - WakeConditionVariable(&m_handle); -#elif defined(_WIN32) - SetEvent(m_handle); -#else - pthread_cond_signal(&m_handle); -#endif - } - - void notify_all() - { -#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES) - WakeAllConditionVariable(&m_handle); -#elif defined(_WIN32) - // TODO: broken - SetEvent(m_handle); -#else - pthread_cond_broadcast(&m_handle); -#endif - } - - void wait(unique_lock& lock) - { -#ifdef _WIN32 - #ifdef USE_SRWLOCKS - SleepConditionVariableSRW(&m_handle, lock.mutex()->native_handle(), INFINITE, 0); - #elif defined(USE_CONDITION_VARIABLES) - SleepConditionVariableCS(&m_handle, lock.mutex()->native_handle(), INFINITE); - #else - // TODO: broken, the unlock and wait need to be atomic - lock.unlock(); - WaitForSingleObject(m_handle, INFINITE); - lock.lock(); - #endif -#else - pthread_cond_wait(&m_handle, lock.mutex()->native_handle()); -#endif - } - - template - void wait(unique_lock& lock, Predicate pred) - { - while (!pred()) - wait(lock); - } - - //template - //cv_status wait_until(unique_lock& lock, - // const chrono::time_point& abs_time); - - //template - // bool wait_until(unique_lock& lock, - // const chrono::time_point& abs_time, - // Predicate pred); - - //template - //cv_status wait_for(unique_lock& lock, - // const chrono::duration& rel_time); - - //template - // bool wait_for(unique_lock& lock, - // const chrono::duration& rel_time, - // Predicate pred); - - native_handle_type native_handle() - { -#ifdef USE_EVENTS - return m_handle; -#else - return &m_handle; -#endif - } - -private: - native_type m_handle; -}; - -} - -#endif -#endif diff --git a/Source/Core/Common/Src/StdMutex.h b/Source/Core/Common/Src/StdMutex.h deleted file mode 100644 index 8a5d22f928..0000000000 --- a/Source/Core/Common/Src/StdMutex.h +++ /dev/null @@ -1,358 +0,0 @@ - -#ifndef MUTEX_H_ -#define MUTEX_H_ - -#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) -#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) - -#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !ANDROID -// GCC 4.4 provides -#include -#else - -// partial implementation for win32/pthread - -#include - -#if defined(_WIN32) -// WIN32 -#define WIN32_LEAN_AND_MEAN -#include - -#else -// POSIX -#include - -#endif - -#if (_MSC_VER >= 1600) || (GCC_VERSION >= GCC_VER(4,3,0) && __GXX_EXPERIMENTAL_CXX0X__) -#define USE_RVALUE_REFERENCES -#endif - -#if defined(_WIN32) && defined(_M_X64) -#define USE_SRWLOCKS -#endif - -namespace std -{ - -class recursive_mutex -{ -#ifdef _WIN32 - typedef CRITICAL_SECTION native_type; -#else - typedef pthread_mutex_t native_type; -#endif - -public: - typedef native_type* native_handle_type; - - recursive_mutex(const recursive_mutex&) /*= delete*/; - recursive_mutex& operator=(const recursive_mutex&) /*= delete*/; - - recursive_mutex() - { -#ifdef _WIN32 - InitializeCriticalSection(&m_handle); -#else - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&m_handle, &attr); -#endif - } - - ~recursive_mutex() - { -#ifdef _WIN32 - DeleteCriticalSection(&m_handle); -#else - pthread_mutex_destroy(&m_handle); -#endif - } - - void lock() - { -#ifdef _WIN32 - EnterCriticalSection(&m_handle); -#else - pthread_mutex_lock(&m_handle); -#endif - } - - void unlock() - { -#ifdef _WIN32 - LeaveCriticalSection(&m_handle); -#else - pthread_mutex_unlock(&m_handle); -#endif - } - - bool try_lock() - { -#ifdef _WIN32 - return (0 != TryEnterCriticalSection(&m_handle)); -#else - return !pthread_mutex_trylock(&m_handle); -#endif - } - - native_handle_type native_handle() - { - return &m_handle; - } - -private: - native_type m_handle; -}; - -#if !defined(_WIN32) || defined(USE_SRWLOCKS) - -class mutex -{ -#ifdef _WIN32 - typedef SRWLOCK native_type; -#else - typedef pthread_mutex_t native_type; -#endif - -public: - typedef native_type* native_handle_type; - - mutex(const mutex&) /*= delete*/; - mutex& operator=(const mutex&) /*= delete*/; - - mutex() - { -#ifdef _WIN32 - InitializeSRWLock(&m_handle); -#else - pthread_mutex_init(&m_handle, NULL); -#endif - } - - ~mutex() - { -#ifdef _WIN32 -#else - pthread_mutex_destroy(&m_handle); -#endif - } - - void lock() - { -#ifdef _WIN32 - AcquireSRWLockExclusive(&m_handle); -#else - pthread_mutex_lock(&m_handle); -#endif - } - - void unlock() - { -#ifdef _WIN32 - ReleaseSRWLockExclusive(&m_handle); -#else - pthread_mutex_unlock(&m_handle); -#endif - } - - bool try_lock() - { -#ifdef _WIN32 - // XXX TryAcquireSRWLockExclusive requires Windows 7! - // return (0 != TryAcquireSRWLockExclusive(&m_handle)); - return false; -#else - return !pthread_mutex_trylock(&m_handle); -#endif - } - - native_handle_type native_handle() - { - return &m_handle; - } - -private: - native_type m_handle; -}; - -#else -typedef recursive_mutex mutex; // just use CriticalSections - -#endif - -enum defer_lock_t { defer_lock }; -enum try_to_lock_t { try_to_lock }; -enum adopt_lock_t { adopt_lock }; - -template -class lock_guard -{ -public: - typedef Mutex mutex_type; - - explicit lock_guard(mutex_type& m) - : pm(m) - { - m.lock(); - } - - lock_guard(mutex_type& m, adopt_lock_t) - : pm(m) - { - } - - ~lock_guard() - { - pm.unlock(); - } - - lock_guard(lock_guard const&) /*= delete*/; - lock_guard& operator=(lock_guard const&) /*= delete*/; - -private: - mutex_type& pm; -}; - -template -class unique_lock -{ -public: - typedef Mutex mutex_type; - - unique_lock() - : pm(NULL), owns(false) - {} - - /*explicit*/ unique_lock(mutex_type& m) - : pm(&m), owns(true) - { - m.lock(); - } - - unique_lock(mutex_type& m, defer_lock_t) - : pm(&m), owns(false) - {} - - unique_lock(mutex_type& m, try_to_lock_t) - : pm(&m), owns(m.try_lock()) - {} - - unique_lock(mutex_type& m, adopt_lock_t) - : pm(&m), owns(true) - {} - - //template - //unique_lock(mutex_type& m, const chrono::time_point& abs_time); - - //template - //unique_lock(mutex_type& m, const chrono::duration& rel_time); - - ~unique_lock() - { - if (owns_lock()) - mutex()->unlock(); - } - -#ifdef USE_RVALUE_REFERENCES - unique_lock& operator=(const unique_lock&) /*= delete*/; - - unique_lock& operator=(unique_lock&& other) - { -#else - unique_lock& operator=(const unique_lock& u) - { - // ugly const_cast to get around lack of rvalue references - unique_lock& other = const_cast(u); -#endif - swap(other); - return *this; - } - -#ifdef USE_RVALUE_REFERENCES - unique_lock(const unique_lock&) /*= delete*/; - - unique_lock(unique_lock&& other) - : pm(NULL), owns(false) - { -#else - unique_lock(const unique_lock& u) - : pm(NULL), owns(false) - { - // ugly const_cast to get around lack of rvalue references - unique_lock& other = const_cast(u); -#endif - swap(other); - } - - void lock() - { - mutex()->lock(); - owns = true; - } - - bool try_lock() - { - owns = mutex()->try_lock(); - return owns; - } - - //template - //bool try_lock_for(const chrono::duration& rel_time); - //template - //bool try_lock_until(const chrono::time_point& abs_time); - - void unlock() - { - mutex()->unlock(); - owns = false; - } - - void swap(unique_lock& u) - { - std::swap(pm, u.pm); - std::swap(owns, u.owns); - } - - mutex_type* release() - { - auto const ret = mutex(); - - pm = NULL; - owns = false; - - return ret; - } - - bool owns_lock() const - { - return owns; - } - - //explicit operator bool () const - //{ - // return owns_lock(); - //} - - mutex_type* mutex() const - { - return pm; - } - -private: - mutex_type* pm; - bool owns; -}; - -template -void swap(unique_lock& x, unique_lock& y) -{ - x.swap(y); -} - -} - -#endif -#endif diff --git a/Source/Core/Common/Src/StdThread.h b/Source/Core/Common/Src/StdThread.h deleted file mode 100644 index 8893c36204..0000000000 --- a/Source/Core/Common/Src/StdThread.h +++ /dev/null @@ -1,310 +0,0 @@ - -#ifndef STD_THREAD_H_ -#define STD_THREAD_H_ - -#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) -#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) - -#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !ANDROID -// GCC 4.4 provides -#ifndef _GLIBCXX_USE_SCHED_YIELD -#define _GLIBCXX_USE_SCHED_YIELD -#endif -#include -#else - -// partial std::thread implementation for win32/pthread - -#include - -#if (_MSC_VER >= 1600) || (GCC_VERSION >= GCC_VER(4,3,0) && __GXX_EXPERIMENTAL_CXX0X__) -#define USE_RVALUE_REFERENCES -#endif - -#ifdef __APPLE__ -#import -#endif - -#if defined(_WIN32) -// WIN32 - -#define WIN32_LEAN_AND_MEAN -#include - -#if defined(_MSC_VER) && defined(_MT) -// When linking with LIBCMT (the multithreaded C library), Microsoft recommends -// using _beginthreadex instead of CreateThread. -#define USE_BEGINTHREADEX -#include -#endif - -#ifdef USE_BEGINTHREADEX -#define THREAD_ID unsigned -#define THREAD_RETURN unsigned __stdcall -#else -#define THREAD_ID DWORD -#define THREAD_RETURN DWORD WINAPI -#endif -#define THREAD_HANDLE HANDLE - -#else -// PTHREAD - -#include - -#ifndef _POSIX_THREADS -#error unsupported platform (no pthreads?) -#endif - -#include - -#define THREAD_ID pthread_t -#define THREAD_HANDLE pthread_t -#define THREAD_RETURN void* - -#endif - -namespace std -{ - -class thread -{ -public: - typedef THREAD_HANDLE native_handle_type; - - class id - { - friend class thread; - public: - id() : m_thread(0) {} - id(THREAD_ID _id) : m_thread(_id) {} - - bool operator==(const id& rhs) const - { - return m_thread == rhs.m_thread; - } - - bool operator!=(const id& rhs) const - { - return !(*this == rhs); - } - - bool operator<(const id& rhs) const - { - return m_thread < rhs.m_thread; - } - - private: - THREAD_ID m_thread; - }; - - // no variadic template support in msvc - //template - //thread(C&& func, A&&... args); - - template - thread(C func) - { - StartThread(new Func(func)); - } - - template - thread(C func, A arg) - { - StartThread(new FuncArg(func, arg)); - } - - thread() /*= default;*/ {} - -#ifdef USE_RVALUE_REFERENCES - thread(const thread&) /*= delete*/; - - thread(thread&& other) - { -#else - thread(const thread& t) - { - // ugly const_cast to get around lack of rvalue references - thread& other = const_cast(t); -#endif - swap(other); - } - -#ifdef USE_RVALUE_REFERENCES - thread& operator=(const thread&) /*= delete*/; - - thread& operator=(thread&& other) - { -#else - thread& operator=(const thread& t) - { - // ugly const_cast to get around lack of rvalue references - thread& other = const_cast(t); -#endif - if (joinable()) - detach(); - swap(other); - return *this; - } - - ~thread() - { - if (joinable()) - detach(); - } - - bool joinable() const - { - return m_id != id(); - } - - id get_id() const - { - return m_id; - } - - native_handle_type native_handle() - { -#ifdef _WIN32 - return m_handle; -#else - return m_id.m_thread; -#endif - } - - void join() - { -#ifdef _WIN32 - WaitForSingleObject(m_handle, INFINITE); - detach(); -#else - pthread_join(m_id.m_thread, NULL); - m_id = id(); -#endif - } - - void detach() - { -#ifdef _WIN32 - CloseHandle(m_handle); -#else - pthread_detach(m_id.m_thread); -#endif - m_id = id(); - } - - void swap(thread& other) - { - std::swap(m_id, other.m_id); -#ifdef _WIN32 - std::swap(m_handle, other.m_handle); -#endif - } - - static unsigned hardware_concurrency() - { -#ifdef _WIN32 - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return static_cast(sysinfo.dwNumberOfProcessors); -#else - return 0; -#endif - } - -private: - id m_id; - -#ifdef _WIN32 - native_handle_type m_handle; -#endif - - template - void StartThread(F* param) - { -#ifdef USE_BEGINTHREADEX - m_handle = (HANDLE)_beginthreadex(NULL, 0, &RunAndDelete, param, 0, &m_id.m_thread); -#elif defined(_WIN32) - m_handle = CreateThread(NULL, 0, &RunAndDelete, param, 0, &m_id.m_thread); -#else - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, 1024 * 1024); - if (pthread_create(&m_id.m_thread, &attr, &RunAndDelete, param)) - m_id = id(); -#endif - } - - template - class Func - { - public: - Func(C _func) : func(_func) {} - - void Run() { func(); } - - private: - C const func; - }; - - template - class FuncArg - { - public: - FuncArg(C _func, A _arg) : func(_func), arg(_arg) {} - - void Run() { func(arg); } - - private: - C const func; - A arg; - }; - - template - static THREAD_RETURN RunAndDelete(void* param) - { -#ifdef __APPLE__ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; -#endif - static_cast(param)->Run(); - delete static_cast(param); -#ifdef __APPLE__ - [pool release]; -#endif - return 0; - } -}; - -namespace this_thread -{ - -inline void yield() -{ -#ifdef _WIN32 - SwitchToThread(); -#else - sleep(0); -#endif -} - -inline thread::id get_id() -{ -#ifdef _WIN32 - return GetCurrentThreadId(); -#else - return pthread_self(); -#endif -} - -} // namespace this_thread - -} // namespace std - -#undef USE_RVALUE_REFERENCES -#undef USE_BEGINTHREADEX -#undef THREAD_ID -#undef THREAD_RETURN -#undef THREAD_HANDLE - -#endif -#endif From 4895e38bd59372e9813bb1b10f36ed49a438808f Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 29 Mar 2013 07:31:15 -0700 Subject: [PATCH 2/7] This change might work better if I git add the files --- CMakeLists.txt | 14 +++++----- Externals/wxWidgets3/build_wx.sh | 4 ++- Externals/wxWidgets3/wx/wxcocoa.h | 28 +++++++++---------- Source/Core/AudioCommon/Src/Mixer.h | 3 +- Source/Core/Common/Common.vcxproj | 5 +--- Source/Core/Common/Common.vcxproj.filters | 5 +--- Source/Core/Common/Src/LogManager.h | 2 +- Source/Core/Common/Src/Thread.h | 13 +++++++-- .../Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h | 2 +- Source/Core/Core/Src/HW/EXI_DeviceMic.h | 2 +- Source/Core/DolphinWX/Src/ConfigMain.cpp | 11 ++------ 11 files changed, 43 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29e41047a1..5b2f436917 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,8 +168,8 @@ if(APPLE) set(ENV{PATH} /usr/bin:/bin:/usr/sbin:/sbin) # Some of our code contains Objective C constructs. - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c -stdlib=libc++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++ -stdlib=libc++") # Avoid mistaking an object file for a source file on the link command line. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -x none") @@ -180,10 +180,10 @@ if(APPLE) # This is inserted into the Info.plist as well. # Note that the SDK determines the maximum version of which optional # features can be used, not the minimum required version to run. - set(OSX_MIN_VERSION "10.5.4") + set(OSX_MIN_VERSION "10.7") set(TARGET_FLAGS "${TARGET_FLAGS} -mmacosx-version-min=${OSX_MIN_VERSION}") - set(SYSROOT_LEGACY_PATH "/Developer/SDKs/MacOSX10.6.sdk") - set(SYSROOT_PATH "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk") + set(SYSROOT_LEGACY_PATH "/Developer/SDKs/MacOSX10.7.sdk") + set(SYSROOT_PATH "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk") if(EXISTS "${SYSROOT_PATH}/") set(TARGET_SYSROOT ${SYSROOT_PATH}) elseif(EXISTS "${SYSROOT_LEGACY_PATH}/") @@ -197,8 +197,8 @@ if(APPLE) # This avoids a warning when linking with QuickTime. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no_arch_warnings") # Specify target CPUs. - set(TARGET_FLAGS "${TARGET_FLAGS} -Xarch_x86_64 -mssse3") - set(TARGET_FLAGS "${TARGET_FLAGS} -Xarch_x86_64 -march=core2") + set(TARGET_FLAGS "${TARGET_FLAGS} -mssse3") + set(TARGET_FLAGS "${TARGET_FLAGS} -march=core2") # Target flags apply to both C and C++ compilation. # CMake passes these to the compiler on the link command line as well. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}") diff --git a/Externals/wxWidgets3/build_wx.sh b/Externals/wxWidgets3/build_wx.sh index 2173572bfa..82670d6e9f 100755 --- a/Externals/wxWidgets3/build_wx.sh +++ b/Externals/wxWidgets3/build_wx.sh @@ -5,7 +5,9 @@ cd wxWidgets case $OSTYPE in darwin*) +export CC=clang CXX=clang++ CFLAGS="-stdlib=libc++" CXXFLAGS="-stdlib=libc++" CPPFLAGS="-stdlib=libc++" BACKEND="osx_cocoa" +ADD_OPTS=--with-macosx-version-min=10.7 --enable-stl ;; linux*) BACKEND="gtk" @@ -15,5 +17,5 @@ esac mkdir build-local cd build-local -../configure --with-$BACKEND --disable-shared --enable-unicode --disable-compat28 --disable-exceptions --disable-fswatcher --without-regex --without-expat --disable-xml --disable-ribbon --disable-propgrid --disable-stc --disable-html --disable-richtext --without-libjpeg --without-libtiff --disable-webview --disable-markup +../configure --with-$BACKEND --disable-shared --enable-unicode --disable-compat28 --disable-exceptions --disable-fswatcher --without-regex --without-expat --disable-xml --disable-ribbon --disable-propgrid --disable-stc --disable-html --disable-richtext --without-libjpeg --without-libtiff --disable-webview --disable-markup $ADD_OPTS make diff --git a/Externals/wxWidgets3/wx/wxcocoa.h b/Externals/wxWidgets3/wx/wxcocoa.h index 841d17e949..33a19cda5b 100644 --- a/Externals/wxWidgets3/wx/wxcocoa.h +++ b/Externals/wxWidgets3/wx/wxcocoa.h @@ -16,7 +16,7 @@ #endif /* __cplusplus */ /* fill in with the string wxGetOsDescription() will return */ -#define WXWIN_OS_DESCRIPTION "Darwin 11.3.0 i386" +#define WXWIN_OS_DESCRIPTION "Darwin 11.4.2 x86_64" /* the installation location prefix from configure */ #define wxINSTALL_PREFIX "/usr/local" @@ -205,7 +205,7 @@ -#define wxUSE_STL 0 +#define wxUSE_STL 1 #if defined(__DMC__) || defined(__WATCOMC__) \ || (defined(_MSC_VER) && _MSC_VER < 1200) @@ -214,7 +214,7 @@ #define wxUSE_STD_DEFAULT 0 #endif -#define wxUSE_STD_CONTAINERS 0 +#define wxUSE_STD_CONTAINERS 1 #define wxUSE_STD_IOSTREAM 1 @@ -715,7 +715,7 @@ /* * Define if your compiler has compliant std::string::compare */ -/* #undef HAVE_STD_STRING_COMPARE */ +#define HAVE_STD_STRING_COMPARE 1 /* * Define if your compiler has */ @@ -736,12 +736,12 @@ /* * Define if your compiler has std::unordered_map */ -/* #undef HAVE_STD_UNORDERED_MAP */ +#define HAVE_STD_UNORDERED_MAP 1 /* * Define if your compiler has std::unordered_set */ -/* #undef HAVE_STD_UNORDERED_SET */ +#define HAVE_STD_UNORDERED_SET 1 /* * Define if your compiler has std::tr1::unordered_map @@ -756,12 +756,12 @@ /* * Define if your compiler has */ -#define HAVE_TR1_TYPE_TRAITS 1 +/* #undef HAVE_TR1_TYPE_TRAITS */ /* * Define if your compiler has */ -/* #undef HAVE_TYPE_TRAITS */ +#define HAVE_TYPE_TRAITS 1 /* * Define if the compiler supports simple visibility declarations. @@ -830,7 +830,7 @@ /* * Define if compiler has __thread keyword. */ -/* #undef HAVE___THREAD_KEYWORD */ +#define HAVE___THREAD_KEYWORD 1 /* * Define if large (64 bit file offsets) files are supported. */ @@ -996,25 +996,25 @@ #define HAVE_USLEEP 1 /* Define if you have wcscasecmp() function */ -/* #undef HAVE_WCSCASECMP 1 */ +#define HAVE_WCSCASECMP 1 /* Define if you have wcsncasecmp() function */ -/* #undef HAVE_WCSNCASECMP 1 */ +#define HAVE_WCSNCASECMP 1 /* Define if you have wcslen function */ #define HAVE_WCSLEN 1 /* Define if you have wcsdup function */ -/* #undef HAVE_WCSDUP 1 */ +#define HAVE_WCSDUP 1 /* Define if you have wcsftime() function */ #define HAVE_WCSFTIME 1 /* Define if you have strnlen() function */ -/* #undef HAVE_STRNLEN 1 */ +#define HAVE_STRNLEN 1 /* Define if you have wcsnlen() function */ -/* #undef HAVE_WCSNLEN 1 */ +#define HAVE_WCSNLEN 1 /* Define if you have wcstoull() and wcstoll() */ /* #undef HAVE_WCSTOULL */ diff --git a/Source/Core/AudioCommon/Src/Mixer.h b/Source/Core/AudioCommon/Src/Mixer.h index a9de2cee72..cbe11e572a 100644 --- a/Source/Core/AudioCommon/Src/Mixer.h +++ b/Source/Core/AudioCommon/Src/Mixer.h @@ -18,8 +18,9 @@ #ifndef _MIXER_H_ #define _MIXER_H_ +#include + #include "WaveFile.h" -#include "StdMutex.h" // 16 bit Stereo #define MAX_SAMPLES (1024 * 8) diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index 822fafe74b..12370296b9 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -241,9 +241,6 @@ - - - @@ -261,4 +258,4 @@ - \ No newline at end of file + diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index d427b70cdd..f8915af9a2 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -85,7 +85,6 @@ - @@ -119,8 +118,6 @@ Crypto - - @@ -134,4 +131,4 @@ {f078f36e-a0ff-4cd0-95f8-476100d68e68} - \ No newline at end of file + diff --git a/Source/Core/Common/Src/LogManager.h b/Source/Core/Common/Src/LogManager.h index f7ccb15034..9c3855982e 100644 --- a/Source/Core/Common/Src/LogManager.h +++ b/Source/Core/Common/Src/LogManager.h @@ -46,7 +46,7 @@ public: void Log(LogTypes::LOG_LEVELS, const char *msg); - bool IsValid() { return (m_logfile != NULL); } + bool IsValid() { return (bool)m_logfile; } bool IsEnabled() const { return m_enable; } void SetEnable(bool enable) { m_enable = enable; } diff --git a/Source/Core/Common/Src/Thread.h b/Source/Core/Common/Src/Thread.h index b5f899c43b..5ced2b2b3e 100644 --- a/Source/Core/Common/Src/Thread.h +++ b/Source/Core/Common/Src/Thread.h @@ -18,9 +18,16 @@ #ifndef _THREAD_H_ #define _THREAD_H_ -#include "StdThread.h" -#include "StdMutex.h" -#include "StdConditionVariable.h" +// has a bug in some versions of libc++: it uses _ as a variable. +// This conflicts with gettext's use of _ as a macro. +#undef _ + +#include +#include +#include + +// Restore _ +#define _(s) wxGetTranslation((s)) // Don't include common.h here as it will break LogManager #include "CommonTypes.h" diff --git a/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h b/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h index 8fd2a2af5f..eb9cf85a5a 100644 --- a/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h +++ b/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h @@ -75,7 +75,7 @@ public: virtual void DoState(PointerWrap& p); // Needed because StdThread.h std::thread implem does not support member - // pointers. + // pointers. TODO(delroth): obsolete. static void SpawnAXThread(CUCode_AX* self); protected: diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMic.h b/Source/Core/Core/Src/HW/EXI_DeviceMic.h index b9596ba85a..4b94f6d723 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceMic.h +++ b/Source/Core/Core/Src/HW/EXI_DeviceMic.h @@ -20,7 +20,7 @@ #if HAVE_PORTAUDIO -#include "StdMutex.h" +#include class CEXIMic : public IEXIDevice { diff --git a/Source/Core/DolphinWX/Src/ConfigMain.cpp b/Source/Core/DolphinWX/Src/ConfigMain.cpp index cbd780e6aa..d3c4a2ac43 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.cpp +++ b/Source/Core/DolphinWX/Src/ConfigMain.cpp @@ -18,6 +18,7 @@ #include // System #include #include +#include #include #include "Common.h" @@ -43,14 +44,6 @@ #include "Main.h" #include "VideoBackendBase.h" -#if defined(__APPLE__) -#include -using std::tr1::function; -#else -#include -using std::function; -#endif - #define TEXT_BOX(page, text) new wxStaticText(page, wxID_ANY, text, wxDefaultPosition, wxDefaultSize) struct CPUCore @@ -631,7 +624,7 @@ void CConfigMain::CreateGUIControls() theme_selection->SetStringSelection(SConfig::GetInstance().m_LocalCoreStartupParameter.theme_name); // std::function = avoid error on msvc - theme_selection->Bind(wxEVT_COMMAND_CHOICE_SELECTED, function([theme_selection](wxEvent&) + theme_selection->Bind(wxEVT_COMMAND_CHOICE_SELECTED, std::function([theme_selection](wxEvent&) { SConfig::GetInstance().m_LocalCoreStartupParameter.theme_name = theme_selection->GetStringSelection(); main_frame->InitBitmaps(); From a8513e46050fe0ae47ff543ec84c2f022e439f6a Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 29 Mar 2013 07:42:41 -0700 Subject: [PATCH 3/7] Re-add StdConditionVariable, MSVC 2010 does not support --- Source/Core/Common/Common.vcxproj | 1 + Source/Core/Common/Common.vcxproj.filters | 1 + Source/Core/Common/Src/StdConditionVariable.h | 166 ++++++++++++++++++ Source/Core/Common/Src/Thread.h | 2 +- 4 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 Source/Core/Common/Src/StdConditionVariable.h diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index 12370296b9..e8e45187b7 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -241,6 +241,7 @@ + diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index f8915af9a2..878ead5d27 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -85,6 +85,7 @@ + diff --git a/Source/Core/Common/Src/StdConditionVariable.h b/Source/Core/Common/Src/StdConditionVariable.h new file mode 100644 index 0000000000..9a045a650b --- /dev/null +++ b/Source/Core/Common/Src/StdConditionVariable.h @@ -0,0 +1,166 @@ + +#ifndef CONDITION_VARIABLE_H_ +#define CONDITION_VARIABLE_H_ + +#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) +#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) + +#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !ANDROID + +// GCC 4.4 provides +#include + +#elif defined(__has_include) && __has_include() + +// clang and libc++ provide on OSX. However, the version +// of libc++ bundled with OSX 10.7 and 10.8 is buggy: it uses _ as a variable. +// +// We work around this issue by undefining and redefining _. + +#undef _ +#include +#define _(s) wxGetTranslation((s)) + +#else + +// partial std::condition_variable implementation for win32/pthread + +#include + +#if (_MSC_VER >= 1600) || (GCC_VERSION >= GCC_VER(4,3,0) && __GXX_EXPERIMENTAL_CXX0X__) +#define USE_RVALUE_REFERENCES +#endif + +#if defined(_WIN32) && defined(_M_X64) +#define USE_CONDITION_VARIABLES +#elif defined(_WIN32) +#define USE_EVENTS +#endif + +namespace std +{ + +class condition_variable +{ +#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES) + typedef CONDITION_VARIABLE native_type; +#elif defined(_WIN32) + typedef HANDLE native_type; +#else + typedef pthread_cond_t native_type; +#endif + +public: + +#ifdef USE_EVENTS + typedef native_type native_handle_type; +#else + typedef native_type* native_handle_type; +#endif + + condition_variable() + { +#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES) + InitializeConditionVariable(&m_handle); +#elif defined(_WIN32) + m_handle = CreateEvent(NULL, false, false, NULL); +#else + pthread_cond_init(&m_handle, NULL); +#endif + } + + ~condition_variable() + { +#if defined(_WIN32) && !defined(USE_CONDITION_VARIABLES) + CloseHandle(m_handle); +#elif !defined(_WIN32) + pthread_cond_destroy(&m_handle); +#endif + } + + condition_variable(const condition_variable&) /*= delete*/; + condition_variable& operator=(const condition_variable&) /*= delete*/; + + void notify_one() + { +#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES) + WakeConditionVariable(&m_handle); +#elif defined(_WIN32) + SetEvent(m_handle); +#else + pthread_cond_signal(&m_handle); +#endif + } + + void notify_all() + { +#if defined(_WIN32) && defined(USE_CONDITION_VARIABLES) + WakeAllConditionVariable(&m_handle); +#elif defined(_WIN32) + // TODO: broken + SetEvent(m_handle); +#else + pthread_cond_broadcast(&m_handle); +#endif + } + + void wait(unique_lock& lock) + { +#ifdef _WIN32 + #ifdef USE_SRWLOCKS + SleepConditionVariableSRW(&m_handle, lock.mutex()->native_handle(), INFINITE, 0); + #elif defined(USE_CONDITION_VARIABLES) + SleepConditionVariableCS(&m_handle, lock.mutex()->native_handle(), INFINITE); + #else + // TODO: broken, the unlock and wait need to be atomic + lock.unlock(); + WaitForSingleObject(m_handle, INFINITE); + lock.lock(); + #endif +#else + pthread_cond_wait(&m_handle, lock.mutex()->native_handle()); +#endif + } + + template + void wait(unique_lock& lock, Predicate pred) + { + while (!pred()) + wait(lock); + } + + //template + //cv_status wait_until(unique_lock& lock, + // const chrono::time_point& abs_time); + + //template + // bool wait_until(unique_lock& lock, + // const chrono::time_point& abs_time, + // Predicate pred); + + //template + //cv_status wait_for(unique_lock& lock, + // const chrono::duration& rel_time); + + //template + // bool wait_for(unique_lock& lock, + // const chrono::duration& rel_time, + // Predicate pred); + + native_handle_type native_handle() + { +#ifdef USE_EVENTS + return m_handle; +#else + return &m_handle; +#endif + } + +private: + native_type m_handle; +}; + +} + +#endif +#endif diff --git a/Source/Core/Common/Src/Thread.h b/Source/Core/Common/Src/Thread.h index 5ced2b2b3e..1eb671f223 100644 --- a/Source/Core/Common/Src/Thread.h +++ b/Source/Core/Common/Src/Thread.h @@ -22,7 +22,7 @@ // This conflicts with gettext's use of _ as a macro. #undef _ -#include +#include "StdConditionVariable.h" #include #include From 38db52061753dac29c7b2b43407ca0bd30ad4aea Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 29 Mar 2013 07:53:45 -0700 Subject: [PATCH 4/7] MSVC 2010 does not have or either, adding the Std* files back --- Source/Core/Common/Common.vcxproj | 4 +- Source/Core/Common/Common.vcxproj.filters | 6 +- Source/Core/Common/Src/StdConditionVariable.h | 6 +- Source/Core/Common/Src/StdMutex.h | 365 ++++++++++++++++++ Source/Core/Common/Src/StdThread.h | 317 +++++++++++++++ Source/Core/Common/Src/Thread.h | 11 +- 6 files changed, 696 insertions(+), 13 deletions(-) create mode 100644 Source/Core/Common/Src/StdMutex.h create mode 100644 Source/Core/Common/Src/StdThread.h diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index e8e45187b7..822fafe74b 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -242,6 +242,8 @@ + + @@ -259,4 +261,4 @@ - + \ No newline at end of file diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index 878ead5d27..d427b70cdd 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -85,7 +85,7 @@ - + @@ -119,6 +119,8 @@ Crypto + + @@ -132,4 +134,4 @@ {f078f36e-a0ff-4cd0-95f8-476100d68e68} - + \ No newline at end of file diff --git a/Source/Core/Common/Src/StdConditionVariable.h b/Source/Core/Common/Src/StdConditionVariable.h index 9a045a650b..952f9e00a2 100644 --- a/Source/Core/Common/Src/StdConditionVariable.h +++ b/Source/Core/Common/Src/StdConditionVariable.h @@ -5,12 +5,16 @@ #define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) #define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#ifndef __has_include +#define __has_include(s) 0 +#endif + #if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !ANDROID // GCC 4.4 provides #include -#elif defined(__has_include) && __has_include() +#elif __has_include() // clang and libc++ provide on OSX. However, the version // of libc++ bundled with OSX 10.7 and 10.8 is buggy: it uses _ as a variable. diff --git a/Source/Core/Common/Src/StdMutex.h b/Source/Core/Common/Src/StdMutex.h new file mode 100644 index 0000000000..a20c7f744a --- /dev/null +++ b/Source/Core/Common/Src/StdMutex.h @@ -0,0 +1,365 @@ + +#ifndef MUTEX_H_ +#define MUTEX_H_ + +#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) +#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) + +#ifndef __has_include +#define __has_include(s) 0 +#endif + +#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !ANDROID +// GCC 4.4 provides +#include +#elif __has_include() +// Clang + libc++ +#include +#else + +// partial implementation for win32/pthread + +#include + +#if defined(_WIN32) +// WIN32 +#define WIN32_LEAN_AND_MEAN +#include + +#else +// POSIX +#include + +#endif + +#if (_MSC_VER >= 1600) || (GCC_VERSION >= GCC_VER(4,3,0) && __GXX_EXPERIMENTAL_CXX0X__) +#define USE_RVALUE_REFERENCES +#endif + +#if defined(_WIN32) && defined(_M_X64) +#define USE_SRWLOCKS +#endif + +namespace std +{ + +class recursive_mutex +{ +#ifdef _WIN32 + typedef CRITICAL_SECTION native_type; +#else + typedef pthread_mutex_t native_type; +#endif + +public: + typedef native_type* native_handle_type; + + recursive_mutex(const recursive_mutex&) /*= delete*/; + recursive_mutex& operator=(const recursive_mutex&) /*= delete*/; + + recursive_mutex() + { +#ifdef _WIN32 + InitializeCriticalSection(&m_handle); +#else + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&m_handle, &attr); +#endif + } + + ~recursive_mutex() + { +#ifdef _WIN32 + DeleteCriticalSection(&m_handle); +#else + pthread_mutex_destroy(&m_handle); +#endif + } + + void lock() + { +#ifdef _WIN32 + EnterCriticalSection(&m_handle); +#else + pthread_mutex_lock(&m_handle); +#endif + } + + void unlock() + { +#ifdef _WIN32 + LeaveCriticalSection(&m_handle); +#else + pthread_mutex_unlock(&m_handle); +#endif + } + + bool try_lock() + { +#ifdef _WIN32 + return (0 != TryEnterCriticalSection(&m_handle)); +#else + return !pthread_mutex_trylock(&m_handle); +#endif + } + + native_handle_type native_handle() + { + return &m_handle; + } + +private: + native_type m_handle; +}; + +#if !defined(_WIN32) || defined(USE_SRWLOCKS) + +class mutex +{ +#ifdef _WIN32 + typedef SRWLOCK native_type; +#else + typedef pthread_mutex_t native_type; +#endif + +public: + typedef native_type* native_handle_type; + + mutex(const mutex&) /*= delete*/; + mutex& operator=(const mutex&) /*= delete*/; + + mutex() + { +#ifdef _WIN32 + InitializeSRWLock(&m_handle); +#else + pthread_mutex_init(&m_handle, NULL); +#endif + } + + ~mutex() + { +#ifdef _WIN32 +#else + pthread_mutex_destroy(&m_handle); +#endif + } + + void lock() + { +#ifdef _WIN32 + AcquireSRWLockExclusive(&m_handle); +#else + pthread_mutex_lock(&m_handle); +#endif + } + + void unlock() + { +#ifdef _WIN32 + ReleaseSRWLockExclusive(&m_handle); +#else + pthread_mutex_unlock(&m_handle); +#endif + } + + bool try_lock() + { +#ifdef _WIN32 + // XXX TryAcquireSRWLockExclusive requires Windows 7! + // return (0 != TryAcquireSRWLockExclusive(&m_handle)); + return false; +#else + return !pthread_mutex_trylock(&m_handle); +#endif + } + + native_handle_type native_handle() + { + return &m_handle; + } + +private: + native_type m_handle; +}; + +#else +typedef recursive_mutex mutex; // just use CriticalSections + +#endif + +enum defer_lock_t { defer_lock }; +enum try_to_lock_t { try_to_lock }; +enum adopt_lock_t { adopt_lock }; + +template +class lock_guard +{ +public: + typedef Mutex mutex_type; + + explicit lock_guard(mutex_type& m) + : pm(m) + { + m.lock(); + } + + lock_guard(mutex_type& m, adopt_lock_t) + : pm(m) + { + } + + ~lock_guard() + { + pm.unlock(); + } + + lock_guard(lock_guard const&) /*= delete*/; + lock_guard& operator=(lock_guard const&) /*= delete*/; + +private: + mutex_type& pm; +}; + +template +class unique_lock +{ +public: + typedef Mutex mutex_type; + + unique_lock() + : pm(NULL), owns(false) + {} + + /*explicit*/ unique_lock(mutex_type& m) + : pm(&m), owns(true) + { + m.lock(); + } + + unique_lock(mutex_type& m, defer_lock_t) + : pm(&m), owns(false) + {} + + unique_lock(mutex_type& m, try_to_lock_t) + : pm(&m), owns(m.try_lock()) + {} + + unique_lock(mutex_type& m, adopt_lock_t) + : pm(&m), owns(true) + {} + + //template + //unique_lock(mutex_type& m, const chrono::time_point& abs_time); + + //template + //unique_lock(mutex_type& m, const chrono::duration& rel_time); + + ~unique_lock() + { + if (owns_lock()) + mutex()->unlock(); + } + +#ifdef USE_RVALUE_REFERENCES + unique_lock& operator=(const unique_lock&) /*= delete*/; + + unique_lock& operator=(unique_lock&& other) + { +#else + unique_lock& operator=(const unique_lock& u) + { + // ugly const_cast to get around lack of rvalue references + unique_lock& other = const_cast(u); +#endif + swap(other); + return *this; + } + +#ifdef USE_RVALUE_REFERENCES + unique_lock(const unique_lock&) /*= delete*/; + + unique_lock(unique_lock&& other) + : pm(NULL), owns(false) + { +#else + unique_lock(const unique_lock& u) + : pm(NULL), owns(false) + { + // ugly const_cast to get around lack of rvalue references + unique_lock& other = const_cast(u); +#endif + swap(other); + } + + void lock() + { + mutex()->lock(); + owns = true; + } + + bool try_lock() + { + owns = mutex()->try_lock(); + return owns; + } + + //template + //bool try_lock_for(const chrono::duration& rel_time); + //template + //bool try_lock_until(const chrono::time_point& abs_time); + + void unlock() + { + mutex()->unlock(); + owns = false; + } + + void swap(unique_lock& u) + { + std::swap(pm, u.pm); + std::swap(owns, u.owns); + } + + mutex_type* release() + { + auto const ret = mutex(); + + pm = NULL; + owns = false; + + return ret; + } + + bool owns_lock() const + { + return owns; + } + + //explicit operator bool () const + //{ + // return owns_lock(); + //} + + mutex_type* mutex() const + { + return pm; + } + +private: + mutex_type* pm; + bool owns; +}; + +template +void swap(unique_lock& x, unique_lock& y) +{ + x.swap(y); +} + +} + +#endif +#endif diff --git a/Source/Core/Common/Src/StdThread.h b/Source/Core/Common/Src/StdThread.h new file mode 100644 index 0000000000..19dfd60c37 --- /dev/null +++ b/Source/Core/Common/Src/StdThread.h @@ -0,0 +1,317 @@ + +#ifndef STD_THREAD_H_ +#define STD_THREAD_H_ + +#define GCC_VER(x,y,z) ((x) * 10000 + (y) * 100 + (z)) +#define GCC_VERSION GCC_VER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) + +#ifndef __has_include +#define __has_include(s) 0 +#endif + +#if GCC_VERSION >= GCC_VER(4,4,0) && __GXX_EXPERIMENTAL_CXX0X__ && !ANDROID +// GCC 4.4 provides +#ifndef _GLIBCXX_USE_SCHED_YIELD +#define _GLIBCXX_USE_SCHED_YIELD +#endif +#include +#elif __has_include() +// Clang + libc++ +#include +#else + +// partial std::thread implementation for win32/pthread + +#include + +#if (_MSC_VER >= 1600) || (GCC_VERSION >= GCC_VER(4,3,0) && __GXX_EXPERIMENTAL_CXX0X__) +#define USE_RVALUE_REFERENCES +#endif + +#ifdef __APPLE__ +#import +#endif + +#if defined(_WIN32) +// WIN32 + +#define WIN32_LEAN_AND_MEAN +#include + +#if defined(_MSC_VER) && defined(_MT) +// When linking with LIBCMT (the multithreaded C library), Microsoft recommends +// using _beginthreadex instead of CreateThread. +#define USE_BEGINTHREADEX +#include +#endif + +#ifdef USE_BEGINTHREADEX +#define THREAD_ID unsigned +#define THREAD_RETURN unsigned __stdcall +#else +#define THREAD_ID DWORD +#define THREAD_RETURN DWORD WINAPI +#endif +#define THREAD_HANDLE HANDLE + +#else +// PTHREAD + +#include + +#ifndef _POSIX_THREADS +#error unsupported platform (no pthreads?) +#endif + +#include + +#define THREAD_ID pthread_t +#define THREAD_HANDLE pthread_t +#define THREAD_RETURN void* + +#endif + +namespace std +{ + +class thread +{ +public: + typedef THREAD_HANDLE native_handle_type; + + class id + { + friend class thread; + public: + id() : m_thread(0) {} + id(THREAD_ID _id) : m_thread(_id) {} + + bool operator==(const id& rhs) const + { + return m_thread == rhs.m_thread; + } + + bool operator!=(const id& rhs) const + { + return !(*this == rhs); + } + + bool operator<(const id& rhs) const + { + return m_thread < rhs.m_thread; + } + + private: + THREAD_ID m_thread; + }; + + // no variadic template support in msvc + //template + //thread(C&& func, A&&... args); + + template + thread(C func) + { + StartThread(new Func(func)); + } + + template + thread(C func, A arg) + { + StartThread(new FuncArg(func, arg)); + } + + thread() /*= default;*/ {} + +#ifdef USE_RVALUE_REFERENCES + thread(const thread&) /*= delete*/; + + thread(thread&& other) + { +#else + thread(const thread& t) + { + // ugly const_cast to get around lack of rvalue references + thread& other = const_cast(t); +#endif + swap(other); + } + +#ifdef USE_RVALUE_REFERENCES + thread& operator=(const thread&) /*= delete*/; + + thread& operator=(thread&& other) + { +#else + thread& operator=(const thread& t) + { + // ugly const_cast to get around lack of rvalue references + thread& other = const_cast(t); +#endif + if (joinable()) + detach(); + swap(other); + return *this; + } + + ~thread() + { + if (joinable()) + detach(); + } + + bool joinable() const + { + return m_id != id(); + } + + id get_id() const + { + return m_id; + } + + native_handle_type native_handle() + { +#ifdef _WIN32 + return m_handle; +#else + return m_id.m_thread; +#endif + } + + void join() + { +#ifdef _WIN32 + WaitForSingleObject(m_handle, INFINITE); + detach(); +#else + pthread_join(m_id.m_thread, NULL); + m_id = id(); +#endif + } + + void detach() + { +#ifdef _WIN32 + CloseHandle(m_handle); +#else + pthread_detach(m_id.m_thread); +#endif + m_id = id(); + } + + void swap(thread& other) + { + std::swap(m_id, other.m_id); +#ifdef _WIN32 + std::swap(m_handle, other.m_handle); +#endif + } + + static unsigned hardware_concurrency() + { +#ifdef _WIN32 + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return static_cast(sysinfo.dwNumberOfProcessors); +#else + return 0; +#endif + } + +private: + id m_id; + +#ifdef _WIN32 + native_handle_type m_handle; +#endif + + template + void StartThread(F* param) + { +#ifdef USE_BEGINTHREADEX + m_handle = (HANDLE)_beginthreadex(NULL, 0, &RunAndDelete, param, 0, &m_id.m_thread); +#elif defined(_WIN32) + m_handle = CreateThread(NULL, 0, &RunAndDelete, param, 0, &m_id.m_thread); +#else + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 1024 * 1024); + if (pthread_create(&m_id.m_thread, &attr, &RunAndDelete, param)) + m_id = id(); +#endif + } + + template + class Func + { + public: + Func(C _func) : func(_func) {} + + void Run() { func(); } + + private: + C const func; + }; + + template + class FuncArg + { + public: + FuncArg(C _func, A _arg) : func(_func), arg(_arg) {} + + void Run() { func(arg); } + + private: + C const func; + A arg; + }; + + template + static THREAD_RETURN RunAndDelete(void* param) + { +#ifdef __APPLE__ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif + static_cast(param)->Run(); + delete static_cast(param); +#ifdef __APPLE__ + [pool release]; +#endif + return 0; + } +}; + +namespace this_thread +{ + +inline void yield() +{ +#ifdef _WIN32 + SwitchToThread(); +#else + sleep(0); +#endif +} + +inline thread::id get_id() +{ +#ifdef _WIN32 + return GetCurrentThreadId(); +#else + return pthread_self(); +#endif +} + +} // namespace this_thread + +} // namespace std + +#undef USE_RVALUE_REFERENCES +#undef USE_BEGINTHREADEX +#undef THREAD_ID +#undef THREAD_RETURN +#undef THREAD_HANDLE + +#endif +#endif diff --git a/Source/Core/Common/Src/Thread.h b/Source/Core/Common/Src/Thread.h index 1eb671f223..e35e73dbe9 100644 --- a/Source/Core/Common/Src/Thread.h +++ b/Source/Core/Common/Src/Thread.h @@ -18,16 +18,9 @@ #ifndef _THREAD_H_ #define _THREAD_H_ -// has a bug in some versions of libc++: it uses _ as a variable. -// This conflicts with gettext's use of _ as a macro. -#undef _ - #include "StdConditionVariable.h" -#include -#include - -// Restore _ -#define _(s) wxGetTranslation((s)) +#include "StdMutex.h" +#include "StdThread.h" // Don't include common.h here as it will break LogManager #include "CommonTypes.h" From 194ada24816c42ae763fe05f82cbaa4bd2ec9cc7 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 29 Mar 2013 07:55:56 -0700 Subject: [PATCH 5/7] More MSVC 2010 build fixes --- Source/Core/AudioCommon/Src/Mixer.h | 3 +-- Source/Core/Common/Src/StdConditionVariable.h | 2 +- Source/Core/Core/Src/HW/EXI_DeviceMic.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/Core/AudioCommon/Src/Mixer.h b/Source/Core/AudioCommon/Src/Mixer.h index cbe11e572a..a9de2cee72 100644 --- a/Source/Core/AudioCommon/Src/Mixer.h +++ b/Source/Core/AudioCommon/Src/Mixer.h @@ -18,9 +18,8 @@ #ifndef _MIXER_H_ #define _MIXER_H_ -#include - #include "WaveFile.h" +#include "StdMutex.h" // 16 bit Stereo #define MAX_SAMPLES (1024 * 8) diff --git a/Source/Core/Common/Src/StdConditionVariable.h b/Source/Core/Common/Src/StdConditionVariable.h index 952f9e00a2..85875fef10 100644 --- a/Source/Core/Common/Src/StdConditionVariable.h +++ b/Source/Core/Common/Src/StdConditionVariable.h @@ -29,7 +29,7 @@ // partial std::condition_variable implementation for win32/pthread -#include +#include "StdMutex.h" #if (_MSC_VER >= 1600) || (GCC_VERSION >= GCC_VER(4,3,0) && __GXX_EXPERIMENTAL_CXX0X__) #define USE_RVALUE_REFERENCES diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMic.h b/Source/Core/Core/Src/HW/EXI_DeviceMic.h index 4b94f6d723..b9596ba85a 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceMic.h +++ b/Source/Core/Core/Src/HW/EXI_DeviceMic.h @@ -20,7 +20,7 @@ #if HAVE_PORTAUDIO -#include +#include "StdMutex.h" class CEXIMic : public IEXIDevice { From 43d862bff93741148e029c118db6ed66cb152541 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Fri, 29 Mar 2013 09:58:30 -0700 Subject: [PATCH 6/7] Keep a frame pointer register on OSX - libunwind seems to crash when it's not present --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b2f436917..13688ae5fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,7 +247,7 @@ if(CMAKE_BUILD_TYPE STREQUAL Debug) set(wxWidgets_USE_DEBUG ON CACHE BOOL "Use wxWidgets Debugging") endif(CMAKE_BUILD_TYPE STREQUAL Debug) -if(CMAKE_BUILD_TYPE STREQUAL Release) +if(CMAKE_BUILD_TYPE STREQUAL Release AND NOT APPLE) add_definitions(-fomit-frame-pointer) endif(CMAKE_BUILD_TYPE STREQUAL Release) From 4d27315cd1c0de85df93bfa859d19741483c06ea Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Sun, 31 Mar 2013 01:55:17 +0100 Subject: [PATCH 7/7] Initialize the AX Thread after the sync objects are initialized --- Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h b/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h index eb9cf85a5a..40466a81dd 100644 --- a/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h +++ b/Source/Core/Core/Src/HW/DSPHLE/UCodes/UCode_AX.h @@ -107,13 +107,13 @@ protected: volatile u16 m_cmdlist[512]; volatile u32 m_cmdlist_size; - std::thread m_axthread; - // Sync objects std::mutex m_processing; std::condition_variable m_cmdlist_cv; std::mutex m_cmdlist_mutex; + std::thread m_axthread; + // Copy a command list from memory to our temp buffer void CopyCmdList(u32 addr, u16 size);