예제 #1
0
GridNumerator::GridNumerator(	Grid **grids,
				Integer Ngrids,
				Comparator<Grid> *gridComparator
		     	)
{
	GridCounterFactory *gridCounterFactory = new GridCounterFactory();

	addToDeleteList(gridCounterFactory);

	m_gridIndex = new GridIndex(
					gridCounterFactory,	//GridDataFactory *gridDataFactory,
					gridComparator		//Comparator<Grid> *gridComparator
				);

	m_grids = (Grid **)malloc( Ngrids * sizeof(Grid *) );

	m_Ngrids = Ngrids;

	Integer i;
	for(i=0; i<Ngrids; i++)
	{
		Counter *counter = (Counter *)m_gridIndex->findData(grids[i]);
		m_grids[counter->getN()] = grids[i];
	}

	

}
예제 #2
0
ThreadPoolJob* ThreadPool::pickNextJobToRun()
{
    OwnedArray<ThreadPoolJob> deletionList;

    {
        const ScopedLock sl (lock);

        for (int i = 0; i < jobs.size(); ++i)
        {
            ThreadPoolJob* job = jobs[i];

            if (job != nullptr && ! job->isActive)
            {
                if (job->shouldStop)
                {
                    jobs.remove (i);
                    addToDeleteList (deletionList, job);
                    --i;
                    continue;
                }

                job->isActive = true;
                return job;
            }
        }
    }

    return nullptr;
}
예제 #3
0
bool ThreadPool::removeJob (ThreadPoolJob* const job,
                            const bool interruptIfRunning,
                            const int timeOutMs)
{
    bool dontWait = true;
    OwnedArray<ThreadPoolJob> deletionList;

    if (job != nullptr)
    {
        const ScopedLock sl (lock);

        if (jobs.contains (job))
        {
            if (job->isActive)
            {
                if (interruptIfRunning)
                    job->signalJobShouldExit();

                dontWait = false;
            }
            else
            {
                jobs.removeFirstMatchingValue (job);
                addToDeleteList (deletionList, job);
            }
        }
    }

    return dontWait || waitForJobToFinish (job, timeOutMs);
}
예제 #4
0
void Parameters::setParameter(const char *name, Parameter *p)
{
	char *upperName=(char*)malloc(strlen(name)+1);
	char s[256];	

	upperString(upperName,name);
//	p->toString(s);
//	printf("setParameter : [%s]=[%s]\n",upperName,s);
	m_text += name;
	m_text += '=';
	m_text += p->toString();
	m_text += ";\n";

	Parameter *pclone = p->clone();
	m_map[upperName] = pclone;
	addToDeleteList(pclone);
	addToDeleteList(new Pointer(upperName));
}
예제 #5
0
bool ThreadPool::removeAllJobs (const bool interruptRunningJobs, const int timeOutMs,
                                ThreadPool::JobSelector* selectedJobsToRemove)
{
    Array <ThreadPoolJob*> jobsToWaitFor;

    {
        OwnedArray<ThreadPoolJob> deletionList;

        {
            const ScopedLock sl (lock);

            for (int i = jobs.size(); --i >= 0;)
            {
                ThreadPoolJob* const job = jobs.getUnchecked(i);

                if (selectedJobsToRemove == nullptr || selectedJobsToRemove->isJobSuitable (job))
                {
                    if (job->isActive)
                    {
                        jobsToWaitFor.add (job);

                        if (interruptRunningJobs)
                            job->signalJobShouldExit();
                    }
                    else
                    {
                        jobs.remove (i);
                        addToDeleteList (deletionList, job);
                    }
                }
            }
        }
    }

    const uint32 start = Time::getMillisecondCounter();

    for (;;)
    {
        for (int i = jobsToWaitFor.size(); --i >= 0;)
        {
            ThreadPoolJob* const job = jobsToWaitFor.getUnchecked (i);

            if (! isJobRunning (job))
                jobsToWaitFor.remove (i);
        }

        if (jobsToWaitFor.size() == 0)
            break;

        if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
            return false;

        jobFinishedSignal.wait (20);
    }

    return true;
}
예제 #6
0
bool ThreadPool::runNextJob()
{
    ThreadPoolJob* const job = pickNextJobToRun();

    if (job == nullptr)
        return false;

    ThreadPoolJob::JobStatus result = ThreadPoolJob::jobHasFinished;

    JUCE_TRY
    {
        result = job->runJob();
    }
    JUCE_CATCH_ALL_ASSERT

    OwnedArray<ThreadPoolJob> deletionList;

    {
        const ScopedLock sl (lock);

        if (jobs.contains (job))
        {
            job->isActive = false;

            if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
            {
                jobs.removeFirstMatchingValue (job);
                addToDeleteList (deletionList, job);

                jobFinishedSignal.signal();
            }
            else
            {
                // move the job to the end of the queue if it wants another go
                jobs.move (jobs.indexOf (job), -1);
            }
        }
    }

    return true;
}