From e2059380de131dacabcfa876368d7aab913857cb Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 22 Feb 2016 16:43:48 +0100 Subject: [PATCH] Cycles: Add easy to use spin lock primitive Currently unused, but will be handy for an upcoming changes. It'll also be nice to be able to do scoped_lock() for both Mutex and Spin, but currently it's not really easy to do, need some changes in typedefs and such, will happen as a separate commit. --- intern/cycles/util/util_thread.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/intern/cycles/util/util_thread.h b/intern/cycles/util/util_thread.h index 9c19235d41d..d9cf452be13 100644 --- a/intern/cycles/util/util_thread.h +++ b/intern/cycles/util/util_thread.h @@ -81,6 +81,29 @@ protected: bool joined; }; +/* Own wrapper around pthread's spin lock to make it's use easier. */ + +class thread_spin_lock { +public: + inline thread_spin_lock() { + pthread_spin_init(&spin_, 0); + } + + inline ~thread_spin_lock() { + pthread_spin_destroy(&spin_); + } + + inline void lock() { + pthread_spin_lock(&spin_); + } + + inline void unlock() { + pthread_spin_unlock(&spin_); + } +protected: + pthread_spinlock_t spin_; +}; + CCL_NAMESPACE_END #endif /* __UTIL_THREAD_H__ */