Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/util/util_thread.cpp
| Show All 20 Lines | |||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| thread::thread(function<void(void)> run_cb, int group) | thread::thread(function<void(void)> run_cb, int group) | ||||
| : run_cb_(run_cb), | : run_cb_(run_cb), | ||||
| joined_(false), | joined_(false), | ||||
| group_(group) | 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); | pthread_create(&pthread_id_, NULL, run, (void*)this); | ||||
| #endif | |||||
| } | } | ||||
| thread::~thread() | thread::~thread() | ||||
| { | { | ||||
| if(!joined_) { | if(!joined_) { | ||||
| join(); | join(); | ||||
| } | } | ||||
| } | } | ||||
| Show All 17 Lines | #endif | ||||
| } | } | ||||
| self->run_cb_(); | self->run_cb_(); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| bool thread::join() | bool thread::join() | ||||
| { | { | ||||
| joined_ = true; | 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; | return pthread_join(pthread_id_, NULL) == 0; | ||||
| #endif | |||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||