Beispiel #1
0
void P4PUpdateManager::updateGuidance(ISP* isp, PGMSelectionManager* sel_mgr)
{
	/* Update peer distributions. Ignore ISP if not found. */
	int rc = sel_mgr->updatePeerDistribution(isp);
	if (rc == ERR_INVALID_ISP)
		return;

	/* Recompute guidance for the desired ISP. Ignore if ISP is not
	 * maintained by this selection manager. */
	rc = sel_mgr->computeGuidance(isp);
	if (rc == ERR_INVALID_ISP)
		return;

	/* Determine the next time selection manager should be updated. Ignore if
	 * we get an error saying ISP is not maintained by the selection manager
	 * (e.g., it could have been removed between computing the guidance and now).*/
	time_t next_compute_time = sel_mgr->getNextComputeTime(isp);
	if (next_compute_time == PGMSelectionManager::TIME_INVALID)
		return;

	/* TODO: Only update swarm-independent if AOE specifies a TTL */

	/* Enqueue a task for the next time guidance should be computed */
	enqueueTask(next_compute_time, TYPE_GUIDANCE, isp, sel_mgr);
}
Beispiel #2
0
void aiContext::updateSamples(float time)
{
    if (m_config.useThreads)
    {
        DebugLog("aiContext::updateSamples() [threaded]");
        
        eachNodes([](aiObject *o) {
            o->readConfig();
        });
        eachNodes([this, time](aiObject *o) {
            enqueueTask([o, time]() {
                o->updateSample(time);
            });
        });
        waitTasks();
        eachNodes([](aiObject *o) {
            o->notifyUpdate();
        });
    }
    else
    {
        DebugLog("aiContext::updateSamples()");
        
        eachNodes([time](aiObject *o) {
            o->updateSample(time);
        });
    }
}
Beispiel #3
0
Simulation::~Simulation() {
	printf("Deleting simulation...\n");
	//enqueue a task which will stop the background thread.
	enqueueTask([]() {throw ThreadTerminationException();});
	backgroundTaskThread.join();
	delete planner;
	printf("Simulation deleted.\n");
}
Beispiel #4
0
void aiContext::updateSamplesBegin(float time)
{
    eachNodes([](aiObject *o) {
        o->readConfig();
    });
    enqueueTask([this, time](){
        eachNodes([time](aiObject *o) {
            o->updateSample(time);
        });
    });
}
Beispiel #5
0
void P4PUpdateManager::updatePDistanceMap(ISP* isp)
{
	/* Get reference to the pDistance map */
	ISPPDistanceMap& pdistmap = isp->getPDistanceMap();

	/* Update P4P information */
	int rc = pdistmap.loadP4PInfo();
	if (rc != 0)
	{
		enqueueTask(time(NULL) + 15 + 60, TYPE_PDISTANCE, isp);
		return;
	}

	/* Enqueue a task for the next time pDistances need to be updated */
	enqueueTask(time(NULL) + pdistmap.getTTL(), TYPE_PDISTANCE, isp);

	/* Enqueue tasks for updating guidance immediately. */
	for (SelectionManagerSet::iterator itr = m_selection_mgrs.begin(); itr != m_selection_mgrs.end(); ++itr)
		enqueueTask(0, TYPE_GUIDANCE, isp, *itr);
}
Beispiel #6
0
void P4PUpdateManager::updatePIDMap(ISP* isp)
{
	/* Get reference to the ISP's PIDMap */
	ISPPIDMap& pidmap = isp->getPIDMap();

	/* Update P4P information */
	int rc = pidmap.loadP4PInfo();
	if (rc != 0)
	{
		/* If there was an error, then we'll just try again later (currently 15 minutes) */
		enqueueTask(time(NULL) + 15 * 60, TYPE_PIDMAP, isp);
		return;
	}

	/* Enqueue a task for the next time the PIDMap needs to be updated */
	enqueueTask(time(NULL) + pidmap.getTTL(), TYPE_PIDMAP, isp);

	/* Enqueue a task to update the pDistance map immediately */
	enqueueTask(0, TYPE_PDISTANCE, isp);
}
Beispiel #7
0
bool P4PUpdateManager::addSelectionManager(PGMSelectionManager* selection_mgr)
{
	if (!m_isp_mgr)
		return false;

	p4p::detail::ScopedExclusiveLock lock(m_mutex);

	SelectionManagerSet::const_iterator itr = m_selection_mgrs.find(selection_mgr);
	if (itr != m_selection_mgrs.end())
		return false;

	m_selection_mgrs.insert(selection_mgr);

	/* Enqueue initial tasks to update guidance information */
	std::vector<ISP*> isps;
	m_isp_mgr->listISPs(isps);

	for (unsigned int i = 0; i < isps.size(); ++i)
		enqueueTask(0, TYPE_GUIDANCE, isps[i], selection_mgr);

	return true;
}
Beispiel #8
0
bool P4PUpdateManager::setISPManager(const ISPManager* isp_mgr)
{
	if (m_isp_mgr)
		return false;

	m_isp_mgr = isp_mgr;

	/* Enqueue initial tasks for updating ISP Info. Once we update
	 * the PID Map, a task will automatically be enqueued to update
	 * the pDistance map. */
	std::vector<ISP*> isps;
	m_isp_mgr->listISPs(isps);

	logTrace("Update manager initialized with %u ISPs", (unsigned int)isps.size());

	for (unsigned int i = 0; i < isps.size(); ++i)
	{
		logTrace("Enqueuing update task for ISP %lx", isps[i]);
		enqueueTask(0, TYPE_PIDMAP, isps[i]);
	}

	return true;
}
Beispiel #9
0
bool QThreadPoolPrivate::tryStart(QRunnable *task)
{
    if (allThreads.isEmpty()) {
        // always create at least one thread
        startThread(task);
        return true;
    }

    // can't do anything if we're over the limit
    if (activeThreadCount() >= maxThreadCount)
        return false;

    if (waitingThreads > 0) {
        // recycle an available thread
        --waitingThreads;
        enqueueTask(task);
        return true;
    }

    if (!expiredThreads.isEmpty()) {
        // restart an expired thread
        QThreadPoolThread *thread = expiredThreads.dequeue();
        Q_ASSERT(thread->runnable == 0);

        ++activeThreads;

        if (task->autoDelete())
            ++task->ref;
        thread->runnable = task;
        thread->start();
        return true;
    }

    // start a new thread
    startThread(task);
    return true;
}
Simulation::~Simulation() {
	//enqueue a task which will stop the background thread.
	enqueueTask([]() {throw ThreadTerminationException();});
	backgroundTaskThread.join();
	delete planner;
}