当前位置: 首页>>代码示例>>C++>>正文


C++ JobQueue类代码示例

本文整理汇总了C++中JobQueue的典型用法代码示例。如果您正苦于以下问题:C++ JobQueue类的具体用法?C++ JobQueue怎么用?C++ JobQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JobQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: callbackOnJobQueue

Continuation callbackOnJobQueue (
    JobQueue& jobQueue, std::string const& name, JobType jobType)
{
    return Continuation ([name, jobType, &jobQueue] (Callback const& cb) {
        jobQueue.addJob (jobType, name, [cb] (Job&) { cb(); });
    });
}
开发者ID:reecer,项目名称:rippled,代码行数:7,代码来源:Yield.cpp

示例2: boss

void boss( ) {
   for (;;) {
      // Get the request from somewhere
      Request req;
      myJobQueue.submitJob(req);
   }
}
开发者ID:jervisfm,项目名称:ExampleCode,代码行数:7,代码来源:12-4.cpp

示例3: while

bool JobManager::processJobs()
{
    m_jobCount = 0;
    m_jobsNotIdle = 0;
    std::list<JobQueue*>::const_iterator it = m_queues.begin();
    for (; it != m_queues.end(); ++it)
        m_jobCount += (*it)->jobCount();

    m_jobsProcessed = 0;
    while (!m_errorOccured && m_jobsProcessed < m_jobCount) {
        // Select a valid queue
        std::list<JobQueue*>::iterator queueIt = m_queues.begin();
        JobQueue* queue = *queueIt;
        while (queue->hasShowStoppers() || queue->isEmpty()) {
            queue = *(++queueIt);
            if (queueIt == m_queues.end())
                goto finish;
        }

        MutexLocker locker(&m_jobsRunningMutex);
        if (m_jobsRunning >= m_maxJobsRunning)
            pthread_cond_wait(&m_needJobsCond, &m_jobsRunningMutex);

        if (m_errorOccured)
            break;

        // Now select a valid job
        if (Job* job = queue->getNextJob()) {
            job->addJobListenner(this);
            job->run();
            m_jobsRunning++;
            m_jobsNotIdle++;
            printReportLine(job);
        }
    }

    finish:

    MutexLocker locker(&m_jobsRunningMutex);
    if (m_jobsRunning) {
        Notice() << "Waiting for unfinished jobs...";
        pthread_cond_wait(&m_allDoneCond, &m_jobsRunningMutex);
    }

    return !m_errorOccured;
}
开发者ID:lucianowolf,项目名称:Meique,代码行数:46,代码来源:jobmanager.cpp

示例4: enqueueStandardSplittingJob

static inline void
enqueueStandardSplittingJob(JobQueue& jobQueue, const LcpCacheStringPtr* inputs, unsigned numInputs, string* output, size_t jobLength)
{
    if (numInputs == 1)
        jobQueue.enqueue(new CopyDataJob(inputs[0], output));

    else if (numInputs <= 2)
        jobQueue.enqueue(new BinaryMergeJob(inputs[0], inputs[1], 0, output));

    else if (numInputs <= 4)
        jobQueue.enqueue(new MergeJobStandardSplitting<4>(inputs, numInputs, output, jobLength));

    else if (numInputs <= 8)
        jobQueue.enqueue(new MergeJobStandardSplitting<8>(inputs, numInputs, output, jobLength));

    else if (numInputs <= 16)
        jobQueue.enqueue(new MergeJobStandardSplitting<16>(inputs, numInputs, output, jobLength));

    else if (numInputs <= 32)
        jobQueue.enqueue(new MergeJobStandardSplitting<32>(inputs, numInputs, output, jobLength));

    else if (numInputs <= 64)
        jobQueue.enqueue(new MergeJobStandardSplitting<64>(inputs, numInputs, output, jobLength));

    else
    {
        DBG(1, "Can't create job with that many streams. Add more cases.");
        abort();
    }
}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例5: run

 virtual size_t run( void )
 {
   for(;;)
   {
     CountPtr< JobQueue::Job > job = q->getJob();
     if( size_t(-1) == job->work( q ) ) return 0;
     Thread::yield();
   }
 }
开发者ID:Elgu,项目名称:rpgml,代码行数:9,代码来源:utest_JobQueue.cpp

示例6: _AddInitJob

/*!	Basic system initialization that must happen before any jobs are launched.
*/
void
LaunchDaemon::_InitSystem()
{
	_AddInitJob(new InitRealTimeClockJob());
	_AddInitJob(new InitSharedMemoryDirectoryJob());
	_AddInitJob(new InitTemporaryDirectoryJob());

	fJobQueue.AddJob(fInitTarget);
}
开发者ID:garodimb,项目名称:haiku,代码行数:11,代码来源:LaunchDaemon.cpp

示例7: FindJob

/*!	Adds the specified \a job to the launch queue
	queue, except those that are triggered by events.

	Unless \c FORCE_NOW is set, the target is only launched if its events,
	if any, have been triggered already.

	Calling this method will trigger a demand event if \c TRIGGER_DEMAND has
	been set.
*/
bool
LaunchDaemon::_LaunchJob(Job* job, uint32 options)
{
	if (job != NULL && (job->IsLaunching() || job->IsRunning()))
		return true;

	if (!_CanLaunchJob(job, options))
		return false;

	// Test if we can launch all requirements
	if (!_CanLaunchJobRequirements(job, options | TRIGGER_DEMAND))
		return false;

	// Actually launch the requirements
	int32 count = job->Requirements().CountStrings();
	for (int32 index = 0; index < count; index++) {
		Job* requirement = FindJob(job->Requirements().StringAt(index));
		if (requirement != NULL) {
			// TODO: For jobs that have their communication channels set up,
			// we would not need to trigger demand at this point
			if (!_LaunchJob(requirement, options | TRIGGER_DEMAND)) {
				// Failed to put a requirement into the launch queue
				return false;
			}
		}
	}

	if (job->Target() != NULL)
		job->Target()->ResolveSourceFiles();
	if (job->Event() != NULL)
		job->Event()->ResetTrigger();

	job->SetLaunching(true);

	status_t status = fJobQueue.AddJob(job);
	if (status != B_OK) {
		debug_printf("Adding job %s to queue failed: %s\n", job->Name(),
			strerror(status));
		return false;
	}

	// Try to launch pending jobs as well
	count = job->Pending().CountStrings();
	for (int32 index = 0; index < count; index++) {
		Job* pending = FindJob(job->Pending().StringAt(index));
		if (pending != NULL && _LaunchJob(pending, 0)) {
			// Remove the job from the pending list once its in the launch
			// queue, so that is not being launched again next time.
			index--;
			count--;
		}
	}

	return true;
}
开发者ID:garodimb,项目名称:haiku,代码行数:64,代码来源:LaunchDaemon.cpp

示例8: main

int main (int argc, char * argv[]) {
    QCoreApplication app(argc, argv);

    JobQueue jq;

    auto a = jq.setTimeout(1000, [&](const qtael::Await & await)->void {
        qDebug() << "A: run callback";
        await(1000);
        qDebug() << "A: first";
        await(1000);
        qDebug() << "A: second";
        await(1000);
        qDebug() << "A: third";
    });

    auto b = jq.setTimeout(1500, [&](const qtael::Await & await)->void {
        qDebug() << "B: run callback";
        await(1000);
        qDebug() << "B: first";
        await(1000);
        qDebug() << "B: second";
        await(1000);
        qDebug() << "B: third";
    });

    auto c = jq.setTimeout(2000, [&](const qtael::Await & /*await*/)->void {
        qDebug() << "C: run callback";
        app.quit();
    });

    auto d = new qtael::Async([&](const qtael::Await & await)->void {
        await(2500);
        qDebug() << "D: run callback";
        jq.clear(b);
    });
    d->connect(d, SIGNAL(finished()), SLOT(deleteLater()));
    d->start();

    return app.exec();
}
开发者ID:legnaleurc,项目名称:qtcoroutine,代码行数:40,代码来源:main.cpp

示例9: parallelLcpMergeStandardSplitting

static inline void
parallelLcpMergeStandardSplitting(const LcpCacheStringPtr* input, unsigned numInputs, string* output, size_t length)
{
    g_outputBase = output;
    g_splittingsExecuted = 0;
    g_mergeJobsCreated = 0;
    g_splittingTime = 0;

    ClockTimer timer;
    timer.start();

    g_outputBase = output;

    JobQueue jobQueue;
    DBG(debug_merge_start_message, "doing parallel lcp merge for " << numInputs << " input streams using " << omp_get_max_threads() << " threads with standard splitting");
    jobQueue.enqueue(new InitialJobStandardSplitting(input, numInputs, output, length));
    jobQueue.numaLoop(-1, omp_get_max_threads());

    g_stats >> "toplevelmerge_time" << timer.elapsed();
    g_stats >> "splittings_executed" << g_splittingsExecuted;
    g_stats >> "mergejobs_created" << g_mergeJobsCreated;
    g_stats >> "splitting_time" << g_splittingTime;
}
开发者ID:,项目名称:,代码行数:23,代码来源:

示例10: FindJob

/*!	Adds the specified \a job to the launch queue
	queue, except those that are triggered by events.

	Unless \a forceNow is true, the target is only launched if its events,
	if any, have been triggered already.

	Calling this method will trigger a demand event.
*/
void
LaunchDaemon::_LaunchJob(Job* job, bool forceNow)
{
	if (job == NULL || job->IsLaunched() || (!forceNow
		&& (!job->EventHasTriggered() || !job->CheckCondition(*this)
			|| Events::TriggerDemand(job->Event())))) {
		return;
	}

	int32 count = job->Requirements().CountStrings();
	for (int32 index = 0; index < count; index++) {
		Job* requirement = FindJob(job->Requirements().StringAt(index));
		if (requirement != NULL)
			_LaunchJob(requirement);
	}

	if (job->Target() != NULL)
		job->Target()->ResolveSourceFiles();
	if (job->Event() != NULL)
		job->Event()->ResetTrigger();

	fJobQueue.AddJob(job);
}
开发者ID:puckipedia,项目名称:haiku,代码行数:31,代码来源:LaunchDaemon.cpp

示例11: mergeToOutput

    /*
     * returns true if all elements have been written to output
     * false if the merge has been stopped to free work.
     */
    inline bool
    mergeToOutput(JobQueue& jobQueue)
    {
        for (size_t lastLength = length; length >= MERGE_BULK_SIZE; length -= MERGE_BULK_SIZE, output += MERGE_BULK_SIZE)
        {
            if (g_lengthOfLongestJob == lastLength)
                g_lengthOfLongestJob = length;

            if (g_lengthOfLongestJob < length)
                g_lengthOfLongestJob = length; // else if to prevent work sharing when we just increased g_lengthOfLongestJob
            else if (USE_WORK_SHARING &&
                     jobQueue.has_idle() &&
                     length > SHARE_WORK_THRESHOLD &&
                     g_lengthOfLongestJob == length)
                return false;

            loserTree.writeElementsToStream(output, MERGE_BULK_SIZE);
            lastLength = length;
        }

        loserTree.writeElementsToStream(output, length);

        return true;
    }
开发者ID:,项目名称:,代码行数:28,代码来源:

示例12: if

    void JobScheduler::run(Ogre::Real time)
    {
        ///@todo use different buckets for jobs not yet started, instead of
        ///      iterating over those each time.

        ///@todo dynamically determine token threshold. Maybe make it work load depending.


        // Queue for finished jobs
        JobQueue notDone;

        for (JobQueue::iterator it = mJobQueue.begin(), end = mJobQueue.end(); it != end; ++it)
        {
            JobEntry entry = *it;

            TimeSource::TimeSourceType tst = entry.job->getTimeSource();
            TimeSource* ts = TimeSourceManager::getSingleton().getTimeSource(tst);
            Time clock = ts->getClock();
            if (tst != entry.timeSourceLastCall) // time source has changed, e.g. in a job queue
            {
                entry.timeLastCall = clock;
                entry.timeSourceLastCall = tst;
            }

            if (entry.markedToRemove)
            {
                // Notify listener, the job was removed
                if (entry.listener != NULL)
                {
                    entry.listener->jobRemoved(entry.ticket);
                }

                if (entry.job->destroyWhenDone() )
                {
                    delete entry.job;
                }
            }
            else if (entry.start <= clock && clock < entry.end)
            {
                // Is the token threshold reached?
                if (entry.tokens >= mTokenThreshold)
                {
                    // Yes, pay run fee and execute.
                    entry.tokens = 0;
                    bool runAgain = !entry.job->execute(clock - entry.timeLastCall);

                    if (!entry.called)
                    {
                        // Notify listener, the job started for the first time
                        if (entry.listener != NULL)
                        {
                            entry.listener->jobStarted(entry.ticket);
                        }
                        entry.called = true;
                    }

                    if (runAgain)
                    {
                        // Job is not done, reset token count and requeue.
                        entry.tokens = entry.priority;
                        entry.timeLastCall = clock;
                        notDone.push_back(entry);
                    }
                    else
                    {
                        // Notify listener, the job finished regularly.
                        if (entry.listener != NULL)
                        {
                            entry.listener->jobFinished(entry.ticket);
                        }

                        // If we are supposed to delete the Job, do so now.
                        if (entry.job->destroyWhenDone())
                        {
                            delete entry.job;
                        }
                    }
                }
                else
                {
                    // No, increase token count
                    entry.tokens += entry.priority;
                    notDone.push_back(entry);
                }
            }
            else if (clock < entry.end)
            {
                // Start time not yet reached. Queue again.
                notDone.push_back(entry);
            }
            else
            {
                // Job reached its end time and didn't want to finish itself, so we do it.
                if (entry.job->isDiscardable())
                {
                    entry.job->discard();
                    if (entry.listener != NULL)
                    {
                        entry.listener->jobDiscarded(entry.ticket);
                    }
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:dsa-hl-svn,代码行数:101,代码来源:JobScheduler.cpp

示例13: run

    virtual bool run(JobQueue& job_queue)
    {
        size_t n = strptr.size();

        LOGC(debug_jobs)
            << "Process SmallsortJob8 " << this << " of size " << n;

        strptr = strptr.copy_back();

        if (n < g_inssort_threshold) {
            inssort::inssort_generic(strptr.copy_back().active(), depth);
            return true;
        }

        Char* charcache = new Char[n];

        // std::deque is much slower than std::vector, so we use an artificial
        // pop_front variable.
        size_t pop_front = 0;
        std::vector<RadixStep8_CI> radixstack;
        radixstack.emplace_back(strptr, depth, charcache);

        while (radixstack.size() > pop_front)
        {
            while (radixstack.back().idx < 255)
            {
                RadixStep8_CI& rs = radixstack.back();
                size_t b = ++rs.idx; // process the bucket rs.idx

                size_t bktsize = rs.bkt[b + 1] - rs.bkt[b];

                if (bktsize == 0)
                    continue;
                else if (bktsize < g_inssort_threshold)
                {
                    inssort::inssort_generic(
                        rs.strptr.sub(rs.bkt[b], bktsize).copy_back().active(),
                        depth + radixstack.size());
                }
                else
                {
                    radixstack.emplace_back(rs.strptr.sub(rs.bkt[b], bktsize),
                                            depth + radixstack.size(),
                                            charcache);
                }

                if (use_work_sharing && job_queue.has_idle())
                {
                    // convert top level of stack into independent jobs
                    LOGC(debug_jobs)
                        << "Freeing top level of SmallsortJob8's radixsort stack";

                    RadixStep8_CI& rt = radixstack[pop_front];

                    while (rt.idx < 255)
                    {
                        b = ++rt.idx; // enqueue the bucket rt.idx

                        size_t bktsize = rt.bkt[b + 1] - rt.bkt[b];

                        if (bktsize == 0) continue;
                        EnqueueSmallsortJob8(
                            job_queue, rt.strptr.sub(rt.bkt[b], bktsize),
                            depth + pop_front);
                    }

                    // shorten the current stack
                    ++pop_front;
                }
            }
            radixstack.pop_back();
        }

        delete[] charcache;

        return true;
    }
开发者ID:bingmann,项目名称:parallel-string-sorting,代码行数:77,代码来源:bingmann-parallel_radix_sort.hpp

示例14: DPRINTF

/**
 * Waits until there is a job in the queue, pops it off and executes
 * it, then waits for another.  Runs until jobs are completed and
 * main thread sets acceptingJobs=0.
 */
void *threadfun(void *arg) {
    DPRINTF(("%s %lu entry\n", __func__, (unsigned long) pthread_self()));

    //    struct timespec timeout;
    JobQueue *jq = (JobQueue *) arg;
    Job *job;
    int status;
    void *threadState = NULL;
    if(jq->ThreadState_new != NULL) {
        threadState = jq->ThreadState_new(jq->threadData);
        CHECKMEM(threadState);
    }

    for(;;) {
        //        clock_gettime(CLOCK_REALTIME, &timeout);
        //        timeout.tv_sec += 3;

        status = pthread_mutex_lock(&jq->lock); // LOCK
        if(status)
            ERR(status, "lock");
        else
            DPRINTF(("%s:%s:%d: locked\n", __FILE__, __func__, __LINE__));

        // Wait while the queue is empty and accepting jobs
        while(NULL == jq->todo && jq->acceptingJobs) {
            DPRINTF(("%s:%d:  awaiting work. todo=%p\n",
                     __func__, __LINE__, jq->todo));

            ++jq->idle;
            if(jq->idle == jq->nThreads) {
                status = pthread_cond_signal(&jq->wakeMain);
                if(status)
                    ERR(status, "signal wakeMain");
            }
            //status = pthread_cond_timedwait(&jq->wakeWorker, &jq->lock,
            //                                &timeout);
            status = pthread_cond_wait(&jq->wakeWorker, &jq->lock);
            --jq->idle;
            //if(status == ETIMEDOUT)
            //    continue;
            if(status)
                ERR(status, "wait wakeWorker");
        }

        /*
         * todo accepting
         *   0     0  <- exit
         *   0     1  <- stay in while loop
         *   1     0  <- do work
         *   1     1  <- do work
         */

        if(NULL == jq->todo) {  // shutting down
            assert(!jq->acceptingJobs);
            break;
        } else {                // do job
            DPRINTF(("%s %lu got work\n", __func__,
                     (unsigned long) pthread_self()));

            // remove job from queue
            assert(NULL != jq->todo);
            job = jq->todo;
            jq->todo = jq->todo->next;

#ifdef DPRINTF_ON
            printf("%s:%d:queue:", __func__, __LINE__);
            Job_print(jq->todo);
#endif

            status = pthread_mutex_unlock(&jq->lock);   // UNLOCK
            if(status)
                ERR(status, "unlock");
            else
                DPRINTF(("%s:%s:%d: unlocked\n", __FILE__, __func__,
                         __LINE__));

            DPRINTF(("%s %lu calling jobfun\n", __func__,
                     (unsigned long) pthread_self()));
            job->jobfun(job->param, threadState);
            DPRINTF(("%s %lu back fr jobfun\n", __func__,
                     (unsigned long) pthread_self()));
            free(job);
        }
    }
    // still have lock
    --jq->nThreads;

    status = pthread_cond_signal(&jq->wakeMain);
    if(status)
        ERR(status, "signal wakeMain");

    status = pthread_mutex_unlock(&jq->lock);   // UNLOCK
    if(status)
        ERR(status, "unlock");
    else
//.........这里部分代码省略.........
开发者ID:alanrogers,项目名称:jobqueue,代码行数:101,代码来源:jobqueue.c

示例15: worker

void worker( ) {
   for (;;) {
      Request r(myJobQueue.getJob( ));
      // Do something with the job...
   }
}
开发者ID:jervisfm,项目名称:ExampleCode,代码行数:6,代码来源:12-4.cpp


注:本文中的JobQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。