// -*- C++ -*- // EPOS-- Synchronizer Abstractions Common Package // This work is licensed under the Creative Commons // Attribution-NonCommercial-NoDerivs License. To view a copy of this license, // visit http://creativecommons.org/licenses/by-nc-nd/2.0/ or send a letter to // Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. #ifndef __synchronizer_h #define __synchronizer_h #include #include //EX2: inclui a nossa fila! #include #include __BEGIN_SYS class Synchronizer_Common { protected: Synchronizer_Common() {} virtual ~Synchronizer_Common() { db(TRC) << "~Synchronizer_Common()\n"; wakeup_all(); } private: static const bool busy_waiting = Traits::busy_waiting; typedef Queue FIFOQueue; protected: FIFOQueue _sleepers; //EX2: definicao da fila de dorminhocos protected: // Atomic operations bool tsl(volatile bool & lock) { return CPU::tsl(lock); } int inc(volatile int & number) { return CPU::finc(number); } int dec(volatile int & number) { return CPU::fdec(number); } // Thread operations void sleep() { if(!busy_waiting){ // configurable feature Thread::sleep(&_sleepers); //EX2: chama o metodo estatico de Thread para colocar running na fila e dormir } } void wakeup() { if(!busy_waiting){ // configurable feature Thread::wakeup(&_sleepers); //EX2: chama o metodo estatico de Thread para acordar o primeiro da fila } } void wakeup_all() { if(!busy_waiting){ // configurable feature Thread::wakeup_all(&_sleepers); //EX2: chama o metodo estatico de Thread para acordar todos da fila } } }; __END_SYS #endif