diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-03-29 16:36:01 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-03-29 16:36:01 +0300 |
commit | 11130970c6a3ff14cb4dd0caece2137891b43e87 (patch) | |
tree | b21d79b38e4ee28ed9762973e8ea1cc604dcfd1b /intern/cycles/util | |
parent | f6ad53804099802ab3f5eafa830f95f8545eb888 (diff) | |
parent | ca5f3dd2200725712a665705fc25e20a208d6295 (diff) |
Merge commit 'origin/master^' into blender2.8
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_sseb.h | 2 | ||||
-rw-r--r-- | intern/cycles/util/util_thread.cpp | 14 | ||||
-rw-r--r-- | intern/cycles/util/util_thread.h | 35 |
3 files changed, 47 insertions, 4 deletions
diff --git a/intern/cycles/util/util_sseb.h b/intern/cycles/util/util_sseb.h index 93c22aafdcd..977976c3fc0 100644 --- a/intern/cycles/util/util_sseb.h +++ b/intern/cycles/util/util_sseb.h @@ -119,7 +119,7 @@ __forceinline const sseb unpacklo( const sseb& a, const sseb& b ) { return _mm_u __forceinline const sseb unpackhi( const sseb& a, const sseb& b ) { return _mm_unpackhi_ps(a, b); } template<size_t i0, size_t i1, size_t i2, size_t i3> __forceinline const sseb shuffle( const sseb& a ) { - return _mm_shuffle_epi32(a, _MM_SHUFFLE(i3, i2, i1, i0)); + return _mm_castsi128_ps(_mm_shuffle_epi32(a, _MM_SHUFFLE(i3, i2, i1, i0))); } template<> __forceinline const sseb shuffle<0, 1, 0, 1>( const sseb& a ) { diff --git a/intern/cycles/util/util_thread.cpp b/intern/cycles/util/util_thread.cpp index 3dcb09804b0..c66aa484264 100644 --- a/intern/cycles/util/util_thread.cpp +++ b/intern/cycles/util/util_thread.cpp @@ -26,7 +26,11 @@ thread::thread(function<void(void)> run_cb, int group) joined_(false), group_(group) { +#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800) + thread_ = std::thread(&thread::run, this); +#else pthread_create(&pthread_id_, NULL, run, (void*)this); +#endif } thread::~thread() @@ -60,7 +64,17 @@ void *thread::run(void *arg) bool thread::join() { joined_ = true; +#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800) + try { + thread_.join(); + return true; + } + catch (const std::system_error&) { + return false; + } +#else return pthread_join(pthread_id_, NULL) == 0; +#endif } CCL_NAMESPACE_END diff --git a/intern/cycles/util/util_thread.h b/intern/cycles/util/util_thread.h index 1e91fb8a706..4d8f464359c 100644 --- a/intern/cycles/util/util_thread.h +++ b/intern/cycles/util/util_thread.h @@ -24,10 +24,16 @@ # include <functional> #else # include <boost/thread.hpp> +# include <pthread.h> #endif -#include <pthread.h> #include <queue> +#ifdef _WIN32 +# include "util_windows.h" +#else +# include <pthread.h> +#endif + #ifdef __APPLE__ # include <libkern/OSAtomic.h> #endif @@ -60,7 +66,11 @@ public: protected: function<void(void)> run_cb_; +#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800) + std::thread thread_; +#else pthread_t pthread_id_; +#endif bool joined_; int group_; }; @@ -81,7 +91,24 @@ public: inline void unlock() { OSSpinLockUnlock(&spin_); } -#else /* __APPLE__ */ +#elif defined(_WIN32) + inline thread_spin_lock() { + const DWORD SPIN_COUNT = 50000; + InitializeCriticalSectionAndSpinCount(&cs_, SPIN_COUNT); + } + + inline ~thread_spin_lock() { + DeleteCriticalSection(&cs_); + } + + inline void lock() { + EnterCriticalSection(&cs_); + } + + inline void unlock() { + LeaveCriticalSection(&cs_); + } +#else inline thread_spin_lock() { pthread_spin_init(&spin_, 0); } @@ -97,10 +124,12 @@ public: inline void unlock() { pthread_spin_unlock(&spin_); } -#endif /* __APPLE__ */ +#endif protected: #ifdef __APPLE__ OSSpinLock spin_; +#elif defined(_WIN32) + CRITICAL_SECTION cs_; #else pthread_spinlock_t spin_; #endif |