コード例 #1
0
ファイル: XmlNodeList.cpp プロジェクト: Andrew-Zhang/fibjs
result_t XmlNodeList::replaceChild(XmlNode_base *newChild, XmlNode_base *oldChild,
                                   obj_ptr<XmlNode_base> &retVal)
{
    XmlNodeImpl *pNew = checkChild(newChild);
    XmlNodeImpl *pOld = checkChild(oldChild);
    if (!pNew || !pOld)
        return CHECK_ERROR(CALL_E_INVALIDARG);

    if (pOld->m_parent != m_this)
        return CHECK_ERROR(Runtime::setError("The node to be replaced is not a child of this node."));

    if (pNew == pOld)
    {
        retVal = newChild;
        return 0;
    }

    if (!checkNew(pNew))
        return CHECK_ERROR(Runtime::setError("The new child element contains the parent."));

    int32_t idx = pOld->m_index;

    pOld->clearParent();

    pNew->setParent(m_this, idx);
    m_childs[idx] = pNew;

    retVal = oldChild;
    return 0;
}
コード例 #2
0
ファイル: XmlNodeList.cpp プロジェクト: Andrew-Zhang/fibjs
result_t XmlNodeList::removeChild(XmlNode_base *oldChild, obj_ptr<XmlNode_base> &retVal)
{
    XmlNodeImpl *pOld = checkChild(oldChild);
    if (!pOld)
        return CHECK_ERROR(CALL_E_INVALIDARG);

    if (pOld->m_parent != m_this)
        return CHECK_ERROR(Runtime::setError("The node to be removed is not a child of this node."));

    int32_t sz = (int32_t)m_childs.size();
    int32_t i;

    for (i = pOld->m_index; i < sz - 1; i ++)
    {
        XmlNodeImpl *pTmp = m_childs[i + 1];
        m_childs[i] = pTmp;
        pTmp->m_index --;
    }
    m_childs.resize(sz - 1);

    pOld->clearParent();

    retVal = oldChild;
    return 0;
}
コード例 #3
0
TIME OptimisticLowOverheadCommSyncAlgo::GetNextTime(TIME currentTime, TIME nextTime)
{
    if(nextTime < grantedTime)
        return grantedTime;
#if DEBUG
    CERR << "Start sync " << currentTime << " " << nextTime << endl;
#endif
    if(currentTime > this->specFailTime){ //we passed beyond spec. failure time. We can speculatie again.
        this->specFailTime=Infinity;
    }

    /*if(this->isChild) //if a child comes here, algorithm is not working!
      throw SyncStateException("Child wants to sync but parent is still alive cannot happen!");*/

    uint64_t diff=interface->reduceTotalSendReceive();

    if(diff > 0)
        this->interface->packetLostCalculator(currentTime);

    TIME minnetworkdelay=interface->reduceNetworkDelay();
    //We never wait for comm sim, instead we wait for oter sims
    TIME specNextTime=Infinity; //netsim follows what the power simulates do
    TIME minNextTime=Infinity;

#ifdef DEBUG
    CERR << "Consensus on message-diff " << diff << endl;
#endif
    if(diff == 0)
        if(!hasChild()){
            interface->aggreateReduceMin(minNextTime,specNextTime);

        }else{
            globalAction=comm->action;
            interface->aggreateReduceMin(minNextTime,globalAction);
        }
        else{//diff!=0 only reduce min op
        	checkChild(diff);
            minNextTime=(TIME)interface->reduceMinTime(Infinity);
            specNextTime=0;
        }
#ifdef DEBUG
    CERR << "Consensus " << minNextTime << " spec: " << specNextTime << endl;
#endif
    //speculation stuff!!
    TIME specResult=testSpeculationState(specNextTime,currentTime);
    if(specResult > 0) //we are in child! We are granted up to specNextTime
        minNextTime=specNextTime;
    //normal convervative algorithm!!!
    //If min time is infinity then there is something with the comm!
    if(minNextTime==Infinity){
#if DEBUG
        CERR << "End Signaled!" << endl;
#endif
        this->finished=true;
        return Infinity;
    }
    this->grantedTime=minNextTime;

    return minNextTime;    
}
コード例 #4
0
ファイル: XmlNodeList.cpp プロジェクト: Andrew-Zhang/fibjs
result_t XmlNodeList::insertAfter(XmlNode_base *newChild, XmlNode_base *refChild,
                                  obj_ptr<XmlNode_base> &retVal)
{
    XmlNodeImpl *pNew = checkChild(newChild);
    XmlNodeImpl *pRef = checkChild(refChild);
    if (!pNew || !pRef)
        return CHECK_ERROR(CALL_E_INVALIDARG);

    if (pRef->m_parent != m_this)
        return CHECK_ERROR(Runtime::setError("The node after which the new node is to be inserted is not a child of this node."));

    if (pNew == pRef)
    {
        retVal = newChild;
        return 0;
    }

    if (!checkNew(pNew))
        return CHECK_ERROR(Runtime::setError("The new child element contains the parent."));

    int32_t sz = (int32_t)m_childs.size();
    int32_t idx = pRef->m_index + 1;
    int32_t i;

    m_childs.resize(sz + 1);

    for (i = sz; i > idx; i --)
    {
        XmlNodeImpl *pTmp = m_childs[i - 1];
        m_childs[i] = pTmp;
        pTmp->m_index ++;
    }

    pNew->setParent(m_this, idx);
    m_childs[idx] = pNew;

    retVal = newChild;
    return 0;
}
コード例 #5
0
ファイル: XmlNodeList.cpp プロジェクト: Andrew-Zhang/fibjs
result_t XmlNodeList::appendChild(XmlNode_base *newChild, obj_ptr<XmlNode_base> &retVal)
{
    XmlNodeImpl *pNew = checkChild(newChild);
    if (!pNew)
        return CHECK_ERROR(CALL_E_INVALIDARG);

    if (!checkNew(pNew))
        return CHECK_ERROR(Runtime::setError("The new child element contains the parent."));

    pNew->setParent(m_this, (int32_t)m_childs.size());
    m_childs.push_back(pNew);

    retVal = newChild;
    return 0;
}
コード例 #6
0
TIME OptimisticTickSyncAlgo::GetNextTime(TIME currentTimeParam, TIME nextTime)
{
	TIME nextEstTime;
	TIME myminNextTime;
	TIME currentTime=currentTimeParam;
	//we have processed upto including grated time
	if(nextTime <= grantedTime){
#ifdef PROFILE
		writeTime(currentTimeParam);
#endif
		return nextTime;
	}

	bool canSpeculate=false;
	bool needToRespond=false;
	busywait=false;
	//send all messages
#if DEBUG
	CERR << "Start sync " << currentTime << " " << nextTime << endl;
#endif
	if(currentTime < grantedTime){ //we still have some granted time we need to barier at granted Time
		busywait=true;
		currentTime=grantedTime;
	}
	if(currentTime > this->specFailTime){ //we passed beyond spec. failure time. We can speculatie again.
		this->specFailTime=Infinity;
	}
	do
	{
		canSpeculate=false;
		if(busywait)
			this->timeStepStart(currentTime);
		//we don't need barier
		uint64_t diff=interface->reduceTotalSendReceive();
		//nextEstTime is the granted time the simulator exptects.
		//myminNextTime is the minimum next time the smulator can process.
		//usually for conservative algorithm these two numbers are the same
		//for optimistic however when get knowledge about the the dead time of child process
		//we can use it as the granted time.
		//if I have a packet, I can only
		nextEstTime=currentTimeParam+Integrator::getOneTimeStep();
		myminNextTime=nextEstTime;
		TIME minnetworkdelay=interface->reduceNetworkDelay();
		if(diff==0 && !needToRespond)
		{ //network stable grant next time
#ifdef DEBUG
			CERR << "diff is 0 specFailTime " << specFailTime << endl;
#endif
			myminNextTime=nextEstTime=nextTime;
			if(specFailTime!=Infinity && nextTime < specFailTime){ //we can grant upto spec fail time
#ifdef DEBUG
				CERR << "I'm grating my self " << specFailTime << endl;
#endif
				nextEstTime=specFailTime;
				//since we know the spec will fail until this time, we won't fork!
				canSpeculate=false;
				//we reset specFailTime.
				specFailTime=Infinity;
			}
			else{
				canSpeculate=true;
			}
		}
		else{
			needToRespond=true;
			//diff changed kill the child process if it is still active.
			checkChild(diff);
		}
		minNextTime=nextEstTime;

#ifdef DEBUG
		CERR << "Consensus on message-diff " << diff << endl;
#endif
		TIME specNextTime=0;
		if(diff==0){
			if(!hasChild()){ //we do speculation calculation only if we can speculate
				//we should never attempt to exchange specDiff when Diff > 0, this is an optimization.
				//canSpeculate can be false regardless of Diff==0, in this case
				//we have simulator that needs to respond. So we need to signal others
				//not to speculate at all.
				TIME mySpecNextTime;

				if(canSpeculate && st->worthSpeculation(currentTime,specFailTime)){ //test if it is worht speculating!
					mySpecNextTime=st->getNextSpecTime(currentTime);
				}
				else{
					mySpecNextTime=0;
				}
				//if we don't have a child, we aggregate specNextTime
				//with with minNextTime
				specNextTime=mySpecNextTime;
				interface->aggreateReduceMin(minNextTime,specNextTime);
			}
			else{
				//if we have child we aggregate action
				//with minNextTime
				this->globalAction=comm->action;
				interface->aggreateReduceMin(minNextTime,this->globalAction);
#ifdef DEBUG
				CERR << comm->action << " " << globalAction << endl;
#endif

			}
		} else{ //well, we have message so we use regular reduce min op.
			minNextTime=(TIME)interface->reduceMinTime(nextEstTime);
		}
		//aggregate reduce min operation.

#ifdef DEBUG
		CERR << "Consensus " << minNextTime << " spec: " << specNextTime << " diff:"<< st->getSpecTime() << endl;
		assert(specNextTime==0 || specNextTime > currentTime);
#endif
		//speculation stuff
		TIME specResult=testSpeculationState(specNextTime,currentTime);
		if(specResult > 0) //we are in child! We are granted up to specNextTime
			minNextTime=specNextTime;

		if(minNextTime==0){ //a sim signal endded
#if DEBUG
			CERR << "End Signaled!" << endl;
#endif
			this->finished=true;
			return 0;
		}

		if(minNextTime < myminNextTime){
			//next time is some seconds away and the simulator has to wait so fork speculative unless we already forked
			//update the value of the currentTime
			currentTimeParam = convertToMyTime(Integrator::getCurSimMetric(),minNextTime);
			currentTimeParam = convertToFrameworkTime(Integrator::getCurSimMetric(),currentTimeParam);
			currentTime = minNextTime;
			busywait=true;
		}
		else{
			busywait=false;
		}

		this->grantedTime=minNextTime;

	}while(busywait);

#ifdef PROFILE
	writeTime(currentTimeParam);
#endif

	return myminNextTime;
}
コード例 #7
0
ファイル: marshall.C プロジェクト: davidheryanto/sc14
    void PUPablePointer(parent *p) {
    	checkChild(p);
    	delete p;
	next();
    }
コード例 #8
0
ファイル: marshall.C プロジェクト: davidheryanto/sc14
    void PUPableReference(parent &p) {
    	checkChild(&p);
	next();
    }
コード例 #9
0
ファイル: marshall.C プロジェクト: davidheryanto/sc14
    void puppedSubclass(pupStruct &s) {
	s.check(); 
	checkChild(s.getSubclass());
	next();
    }