1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_SPINLOCK_HPP
- #define __BOOST_SORT_PARALLEL_DETAIL_UTIL_SPINLOCK_HPP
- #include <ciso646>
- #include <atomic>
- #include <ctime>
- #include <functional>
- #include <memory>
- #include <mutex>
- #include <thread>
- namespace boost
- {
- namespace sort
- {
- namespace common
- {
- class spinlock_t
- {
- private:
-
-
-
- std::atomic_flag af;
- public:
-
-
-
-
-
-
- explicit spinlock_t ( ) noexcept { af.clear ( ); };
-
-
-
-
-
- void lock ( ) noexcept
- {
- while (af.test_and_set (std::memory_order_acquire))
- {
- std::this_thread::yield ( );
- };
- };
-
-
-
-
-
-
-
- bool try_lock ( ) noexcept
- {
- return !af.test_and_set (std::memory_order_acquire);
- };
-
-
-
-
-
- void unlock ( ) noexcept { af.clear (std::memory_order_release); };
- };
- };
- };
- };
- #endif
|