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