//--------------------------------------------------------- // spinlock.h: stallings + interruptor(con spinlock) //--------------------------------------------------------- #include #include //--------------------------------------------------------- class interruptor { public: void lock(std::mutex &llave) { while (spinlock.test() || spinlock.test_and_set()); if (++contador == 1) llave.lock(); spinlock.clear(); } void unlock(std::mutex &llave) { while (spinlock.test() || spinlock.test_and_set()); if (--contador == 0) llave.unlock(); spinlock.clear(); } protected: std::atomic_flag spinlock; size_t contador = 0; }; //---------------------------------------------------------