예제 #1
0
	virtual bool SetLanePriorityTo (Plane::PlaneDirection direction, int idLane)
	{
		_mLanes->Wait();
		if (!_bLanes[idLane])
		{
			_mLanes->Signal();
			return false;
		}
		_pdLanes[idLane] = direction;
		_mLanes->Signal();
		return true;
	}
예제 #2
0
	void SignalRespectiveWaitingList(Plane::PlaneDirection pd)
	{
		if(pd==Plane::LAND && _planeListToLand->next != _planeListToLand 
			|| pd==Plane::LIFTOFF && _planeListToLift->next == _planeListToLift)
		{
			_sWaitingListLanding->Signal();
		}
		else if(pd==Plane::LIFTOFF && _planeListToLift->next != _planeListToLift 
			|| pd==Plane::LAND && _planeListToLand->next == _planeListToLand)
		{
			_sWaitingListLiftoff->Signal();
		}
	}
예제 #3
0
	//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;
	}
예제 #4
0
	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();
	}
예제 #5
0
	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();
	}
예제 #6
0
	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);
	}