Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/util/util_thread.h
| Show All 11 Lines | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef __UTIL_THREAD_H__ | #ifndef __UTIL_THREAD_H__ | ||||
| #define __UTIL_THREAD_H__ | #define __UTIL_THREAD_H__ | ||||
| #if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800) | |||||
| # include <thread> | #include <thread> | ||||
| # include <mutex> | #include <mutex> | ||||
| # include <condition_variable> | #include <condition_variable> | ||||
| # include <functional> | #include <functional> | ||||
| #else | |||||
| # include <boost/thread.hpp> | |||||
| # include <pthread.h> | |||||
| #endif | |||||
| #include <queue> | #include <queue> | ||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||
| # include "util_windows.h" | # include "util_windows.h" | ||||
| #else | #else | ||||
| # include <pthread.h> | # include <pthread.h> | ||||
| #endif | #endif | ||||
| #ifdef __APPLE__ | #ifdef __APPLE__ | ||||
| # include <libkern/OSAtomic.h> | # include <libkern/OSAtomic.h> | ||||
| #endif | #endif | ||||
| #include "util/util_function.h" | #include "util/util_function.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| #if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800) | |||||
| typedef std::mutex thread_mutex; | typedef std::mutex thread_mutex; | ||||
| typedef std::unique_lock<std::mutex> thread_scoped_lock; | typedef std::unique_lock<std::mutex> thread_scoped_lock; | ||||
| typedef std::condition_variable thread_condition_variable; | typedef std::condition_variable thread_condition_variable; | ||||
| #else | |||||
| /* use boost for mutexes */ | |||||
| typedef boost::mutex thread_mutex; | |||||
| typedef boost::mutex::scoped_lock thread_scoped_lock; | |||||
| typedef boost::condition_variable thread_condition_variable; | |||||
| #endif | |||||
| /* own pthread based implementation, to avoid boost version conflicts with | /* own pthread based implementation, to avoid boost version conflicts with | ||||
| * dynamically loaded blender plugins */ | * dynamically loaded blender plugins */ | ||||
| class thread { | class thread { | ||||
| public: | public: | ||||
| thread(function<void(void)> run_cb, int group = -1); | thread(function<void(void)> run_cb, int group = -1); | ||||
| ~thread(); | ~thread(); | ||||
| static void *run(void *arg); | static void *run(void *arg); | ||||
| bool join(); | bool join(); | ||||
| protected: | protected: | ||||
| function<void(void)> run_cb_; | function<void(void)> run_cb_; | ||||
| #if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800) | |||||
| std::thread thread_; | std::thread thread_; | ||||
| #else | |||||
| pthread_t pthread_id_; | |||||
| #endif | |||||
| bool joined_; | bool joined_; | ||||
| int group_; | int group_; | ||||
| }; | }; | ||||
| /* Own wrapper around pthread's spin lock to make it's use easier. */ | /* Own wrapper around pthread's spin lock to make it's use easier. */ | ||||
| class thread_spin_lock { | class thread_spin_lock { | ||||
| public: | public: | ||||
| ▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines | |||||