123456789101112131415161718192021222324 |
- #ifndef _ATOMIC_LOCK_HPP_
- #define _ATOMIC_LOCK_HPP_
- #include <atomic>
- struct atomic_lock
- {
- std::atomic<int>&mutex_;
- atomic_lock (std::atomic<int>&mutex)
- :mutex_(mutex)
- {
- int ex=0;
- while(!mutex_.compare_exchange_weak(ex,1))
- {
- }
- }
- ~atomic_lock()
- {
- mutex_.store(0);
- }
- };
- #endif
|