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 <mutex> | |||||
| # include <condition_variable> | |||||
| # include <functional> | |||||
| #else | |||||
| #include <boost/thread.hpp> | # include <boost/thread.hpp> | ||||
| #endif | |||||
| #include <pthread.h> | #include <pthread.h> | ||||
| #include <queue> | #include <queue> | ||||
| #include "util_function.h" | #include "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::unique_lock<std::mutex> thread_scoped_lock; | |||||
| typedef std::condition_variable thread_condition_variable; | |||||
| #else | |||||
| /* use boost for mutexes */ | /* use boost for mutexes */ | ||||
| typedef boost::mutex thread_mutex; | typedef boost::mutex thread_mutex; | ||||
| typedef boost::mutex::scoped_lock thread_scoped_lock; | typedef boost::mutex::scoped_lock thread_scoped_lock; | ||||
| typedef boost::condition_variable thread_condition_variable; | 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(boost::function<void(void)> run_cb_) | thread(function<void(void)> run_cb_) | ||||
sergeyUnsubmitted Not Done Inline Actionssergey: thread(function<void(void)> run_cb_) ? | |||||
| { | { | ||||
| joined = false; | joined = false; | ||||
| run_cb = run_cb_; | run_cb = run_cb_; | ||||
| pthread_create(&pthread_id, NULL, run, (void*)this); | pthread_create(&pthread_id, NULL, run, (void*)this); | ||||
| } | } | ||||
| ~thread() | ~thread() | ||||
| Show All 10 Lines | public: | ||||
| bool join() | bool join() | ||||
| { | { | ||||
| joined = true; | joined = true; | ||||
| return pthread_join(pthread_id, NULL) == 0; | return pthread_join(pthread_id, NULL) == 0; | ||||
| } | } | ||||
| protected: | protected: | ||||
| boost::function<void(void)> run_cb; | function<void(void)> run_cb; | ||||
| pthread_t pthread_id; | pthread_t pthread_id; | ||||
| bool joined; | bool joined; | ||||
| }; | }; | ||||
Not Done Inline Actionsfunction<void(void)> run_cb; ? sergey: function<void(void)> run_cb; ? | |||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| #endif /* __UTIL_THREAD_H__ */ | #endif /* __UTIL_THREAD_H__ */ | ||||