-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor rework of SpinLock class for making it more efficient on Unlock() #33
Conversation
noSTALKER
commented
May 17, 2019
- atomic_flag is initialized using the recommended ATOMIC_FLAG_INIT
- Unlock() function clears the atomic_flag using more efficient std::memory_order_acquire
- Unlock() and Lock() methods are now both noexcept
- Removed unnecessary include files
Just a query for future. I haven't seen |
Also the the functions are name |
Currently we don't have intention to use or not to use noexcept. Please feel free to use it in your PR. We will do refactoring and add it into readme if it becomes an explicit requirement in the future. |
|
||
SpinLock(const SpinLock&) = delete; | ||
SpinLock& operator = (const SpinLock&) = delete; | ||
|
||
private: | ||
std::atomic_flag m_lock; | ||
std::atomic_flag m_lock = ATOMIC_FLAG_INIT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I don't recommend to use default member initializer since it may become confused and hard to read when there are multiple data members or constructors. But it should be fine here since it is the only data member and all implementation is in same file now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the recommended way of in initializing std::atomic_flag
, that is why i didn't used it in initializer list as it requires copy initialization using the ATOMIC_FLAG_INIT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace the tabs with spaces.
…() (microsoft#33) * Minor rework of SpinLock class for making it more efficient on Unlock() * remove tabs in Concurrent.h class