virtual void fecharPista (int idPista) { _mLanes->Wait(); if(_pdLanes[idPista]==Plane::LAND) _pdLanes[idPista]=Plane::LAND_CLOSED; else _pdLanes[idPista]=Plane::LIFT_CLOSED; _mLanes->Signal(); }
virtual void abrirPista (int idPista) { _mLanes->Wait(); if(_pdLanes[idPista]==Plane::LAND_CLOSED) _pdLanes[idPista]=Plane::LAND; else _pdLanes[idPista]=Plane::LIFTOFF; SignalRespectiveWaitingList(_pdLanes[idPista]); _mLanes->Signal(); }
virtual void libertarPista(Plane * p) { if(!p->_finishedWork) return; _mLanes->Wait(); _bLanes[p->_idLane]=true; Plane::PlaneDirection pd = _pdLanes[p->_idLane]; _mLanes->Signal(); SignalRespectiveWaitingList(pd); }
virtual bool SetLanePriorityTo (Plane::PlaneDirection direction, int idLane) { _mLanes->Wait(); if (!_bLanes[idLane]) { _mLanes->Signal(); return false; } _pdLanes[idLane] = direction; _mLanes->Signal(); return true; }
//As threads são desbloqueadas através de um método que indicará //qual a pista a libertar e consoante a sua prioridade irá libertar //uma thread da lista correspondente ou uma de outra, caso não haja. virtual Plane * UseLaneTo(Plane::PlaneDirection direction, Plane * planeList, Semaforo * mPlaneList, Semaforo * sWaitingList) { mPlaneList->Wait(); Plane * p = AddNewPlaneInEndOf(planeList,direction); p->_finishedWork = false; mPlaneList->Signal(); do{ _mLanes->Wait(); int nLane = findLaneTo(direction); if(nLane == -1) { if(direction==Plane::LAND && _planeListToLift->next==_planeListToLift) { nLane = findLaneTo(Plane::LIFTOFF); } else if(direction==Plane::LIFTOFF && _planeListToLand->next==_planeListToLand) { nLane = findLaneTo(Plane::LAND); } if(nLane==-1) { _mLanes->Signal(); sWaitingList->Wait(); } } if(nLane!=-1) { _bLanes[nLane]=false; _mLanes->Signal(); //obter o aviao consoante a direccao mPlaneList->Wait(); p = planeList->next; Remove(p); mPlaneList->Signal(); p->_finishedWork = true; p->_idLane = nLane; break; } }while(true); return p; }