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.
This commit is contained in:
@@ -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__ */
|
||||
|
Reference in New Issue
Block a user