本文整理汇总了C++中internaljob::Pointer类的典型用法代码示例。如果您正苦于以下问题:C++ Pointer类的具体用法?C++ Pointer怎么用?C++ Pointer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pointer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Schedule
void JobManager::Schedule(InternalJob::Pointer job, Poco::Timestamp::TimeDiff delay, bool reschedule)
{
if (!m_active)
throw Poco::IllegalStateException("Job manager has been shut down.");
poco_assert(job); // "Job is null"
poco_assert(delay >= 0); // "Scheduling delay is negative"
{
Poco::ScopedLock<Poco::Mutex> managerLock (m_mutex);
//if the job is already running, set it to be rescheduled when done
if (job->GetState() == Job::RUNNING)
{
job->SetStartTime(delay);
return;
}
//can't schedule a job that is waiting or sleeping
if (job->InternalGetState() != Job::NONE)
return;
//remember that we are about to schedule the job
//to prevent multiple schedule attempts from succeeding (bug 68452)
InternalJob::Pointer sptr_job(job);
ChangeState(sptr_job, InternalJob::ABOUT_TO_SCHEDULE);
}
//notify listeners outside sync block
m_JobListeners.Scheduled(job.Cast<Job>(), delay, reschedule);
//schedule the job
DoSchedule(job, delay);
//call the pool outside sync block to avoid deadlock
m_Pool->JobQueued();
}
示例2: Sleep
bool JobManager::Sleep(InternalJob::Pointer job)
{
{
Poco::ScopedLock<Poco::Mutex> lockMe (m_mutex);
InternalJob::Pointer sptr_job(job);
switch (job->GetState())
{
case Job::RUNNING :
//cannot be paused if it is already running (as opposed to ABOUT_TO_RUN)
if (job->InternalGetState() == Job::RUNNING)
return false;
//job hasn't started running yet (aboutToRun listener)
break;
case Job::SLEEPING :
//update the job wake time
job->SetStartTime(InternalJob::T_INFINITE);
//change state again to re-shuffle the sleep queue
ChangeState(sptr_job, Job::SLEEPING);
return true;
case Job::NONE :
return true;
case Job::WAITING :
//put the job to sleep
break;
}
job->SetStartTime(InternalJob::T_INFINITE);
ChangeState(sptr_job, Job::SLEEPING);
}
m_JobListeners.Sleeping(job.Cast<Job>());
return true;
}
示例3: IsBlocking
bool JobManager::IsBlocking(InternalJob::Pointer sptr_runningJob)
{
{
Poco::ScopedLock<Poco::Mutex> lockMe (m_mutex);
// if this job isn't running, it can't be blocking anyone
if (sptr_runningJob->GetState() != Job::RUNNING)
return false;
// if any job is queued behind this one, it is blocked by it
InternalJob::Pointer ptr_previous = sptr_runningJob->Previous();
while (ptr_previous != 0)
{
// ignore jobs of lower priority (higher priority value means lower priority)
if (ptr_previous->GetPriority() < sptr_runningJob->GetPriority())
{
if (!ptr_previous->IsSystem())
return true;
// TODO Implicit Jobs
// implicit jobs should interrupt unless they act on behalf of system jobs
// if (previous instanceof ThreadJob && ((ThreadJob) previous).shouldInterrupt())
// return true;
}
ptr_previous = ptr_previous->previous;
}
// none found
return false;
}
}
示例4: RunNow
bool JobManager::RunNow(InternalJob::Pointer sptr_job)
{
{
Poco::ScopedLock<Poco::Mutex> lockMe (m_mutex);
//cannot start if there is a conflicting job
if (FindBlockingJob(sptr_job) != 0)
return false;
ChangeState(sptr_job, Job::RUNNING);
sptr_job->SetProgressMonitor(IProgressMonitor::Pointer(new NullProgressMonitor()));
sptr_job->Run(IProgressMonitor::Pointer(nullptr));
}
return true;
}
示例5: FindBlockingJob
InternalJob::Pointer JobManager::FindBlockingJob(InternalJob::Pointer waitingJob)
{
if (waitingJob->GetRule() == 0)
return InternalJob::Pointer(nullptr);
{
Poco::ScopedLock<Poco::Mutex> managerLock (m_mutex);
if (m_running.empty() )
{
InternalJob::Pointer dummy;
return (dummy);
}
//check the running jobs
bool hasBlockedJobs = false;
QSet<InternalJob::Pointer>::Iterator it;
for ( it = m_running.begin(); it != m_running.end(); it ++ )
{
InternalJob::Pointer sptr_job = *it ++;
if (waitingJob->IsConflicting(sptr_job))
return sptr_job;
if (!hasBlockedJobs)
hasBlockedJobs = sptr_job->Previous() != 0;
}
// there are no blocked jobs, so we are done
if (!hasBlockedJobs)
{
InternalJob::Pointer dummy;
return (dummy);
}
//check all jobs blocked by running jobs
QSet<InternalJob::Pointer>::Iterator it_blocked;
for( it_blocked = m_running.begin(); it_blocked != m_running.end(); it_blocked ++ )
{
InternalJob::Pointer sptr_job = *it_blocked ++;
while (true)
{
sptr_job = sptr_job->Previous();
if (sptr_job == 0)
break;
if (waitingJob->IsConflicting(sptr_job))
return sptr_job;
}
}
}
InternalJob::Pointer sptr_null;
return (sptr_null);
}
示例6: CreateMonitor
IProgressMonitor::Pointer JobManager::CreateMonitor(InternalJob::Pointer sptr_job, IProgressMonitor::Pointer group, int ticks)
{
{
Poco::ScopedLock<Poco::Mutex> managerLock(m_mutex);
//group must be set before the job is scheduled
//this includes the ABOUT_TO_SCHEDULE state, during which it is still
//valid to set the progress monitor
if (sptr_job->GetState() != Job::NONE)
{
IProgressMonitor::Pointer dummy(nullptr);
return dummy;
}
IProgressMonitor::Pointer sptr_monitor(nullptr);
if (m_sptr_progressProvider != 0)
sptr_monitor = m_sptr_progressProvider->CreateMonitor(sptr_job.Cast<Job>() , group, ticks);
if (sptr_monitor == 0)
{
// return a default NullprogressMonitor
NullProgressMonitor::Pointer sptr_defaultMonitor(new NullProgressMonitor() );
return sptr_defaultMonitor;
}
return sptr_monitor;
}
}
示例7: DoSchedule
void JobManager::DoSchedule(InternalJob::Pointer job,
Poco::Timestamp::TimeDiff delay)
{
Poco::ScopedLock<Poco::Mutex> managerLock(m_mutex);
//job may have been canceled already
int state = job->InternalGetState();
if (state != InternalJob::ABOUT_TO_SCHEDULE && state != Job::SLEEPING)
return;
//if it's a decoration job with no rule, don't run it right now if the system is busy
if (job->GetPriority() == Job::DECORATE && job->GetRule() == 0)
{
Poco::Timestamp::TimeDiff tmp_minDelay = m_running.size() * 100;
delay = std::max(delay, tmp_minDelay);
}
if (delay > 0)
{
job->SetStartTime(Poco::Timestamp() + delay * 100);
InternalJob::Pointer sptr_job(job);
ChangeState(sptr_job, Job::SLEEPING);
}
else
{
job->SetStartTime(Poco::Timestamp() + DelayFor(job->GetPriority()) * 100);
job->SetWaitQueueStamp(m_waitQueueCounter++);
InternalJob::Pointer sptr_job(job);
ChangeState(sptr_job, Job::WAITING);
}
}
示例8: SetPriority
void JobManager::SetPriority(InternalJob::Pointer job, int newPriority)
{
{
Poco::ScopedLock<Poco::Mutex> lockMe (m_mutex);
InternalJob::Pointer sptr_job(job);
int oldPriority = job->GetPriority();
if (oldPriority == newPriority)
return;
job->InternalSetPriority(newPriority);
//if the job is waiting to run, re-shuffle the queue
if (sptr_job->GetState() == Job::WAITING)
{
Poco::Timestamp oldStart = job->GetStartTime();
job->SetStartTime(oldStart += (DelayFor(newPriority) - DelayFor(oldPriority)));
m_JobQueueWaiting.Resort(job);
}
}
}
示例9: ReportBlocked
void JobManager::ReportBlocked(IProgressMonitor::Pointer sptr_monitor, InternalJob::Pointer sptr_blockingJob) const {
if ( sptr_monitor.Cast<IProgressMonitorWithBlocking>() == 0 )
return ;
if (sptr_blockingJob == 0 || sptr_blockingJob->IsSystem())
{
Status::Pointer sptr_reason( new Status(IStatus::INFO_TYPE, JobManager::PI_JOBS(), 1, "the user operation is waiting for background work to complete" ) );
}
else
{
std::stringstream msg ;
msg << "the user operation is waiting for : " << sptr_blockingJob->GetName() << " to complete. " ;
JobStatus::Pointer sptr_reason(new JobStatus(IStatus::INFO_TYPE, sptr_blockingJob.Cast<Job>(), msg.str() ));
}
// ((IProgressmonitorWithBlocking) sptr_monitor)->SetBlocked(sptr_reason);
}
示例10: IsConflicting
bool InternalJob::IsConflicting(InternalJob::Pointer otherJob) const
{
ISchedulingRule::Pointer otherRule = otherJob->GetRule();
if (sptr_schedulingRule.GetPointer() == 0 || otherRule.GetPointer() == 0)
return false;
// TODO MultiRule: extend the IsConflicting (...) method with MultiRule
// if one of the rules is a compound rule, it must be asked the question.
//if (schedulingRule.GetClass() == MultiRule.class)
// return schedulingRule.IsConflicting(otherRule);
return otherRule->IsConflicting(sptr_schedulingRule);
}
示例11: CanOvertake
bool JobQueue::CanOvertake(InternalJob::Pointer newEntry,
InternalJob::Pointer queueEntry)
{
//can never go past the end of the queue
if (queueEntry == dummy.GetPointer())
return false;
//if the new entry was already in the wait queue, ensure it is re-inserted in correct position (bug 211799)
if (newEntry->GetWaitQueueStamp() > 0 && newEntry->GetWaitQueueStamp()
< queueEntry->GetWaitQueueStamp())
return true;
//if the new entry has lower priority, there is no need to overtake the existing entry
if ((queueEntry == newEntry))
return false;
// the new entry has higher priority, but only overtake the existing entry if the queue allows it
InternalJob::Pointer sptr_queueEntry(queueEntry);
return m_allowConflictOvertaking || !newEntry->IsConflicting(sptr_queueEntry);
}
示例12: SetRule
void JobManager::SetRule(InternalJob::Pointer job,
ISchedulingRule::Pointer sptr_rule)
{
Poco::ScopedLock<Poco::Mutex> m_managerLock(m_mutex);
//cannot change the rule of a job that is already running ( GetRule is set to protected which should be
// changed if this assert is needed
// assert(job->GetState() == Job.NONE);
ValidateRule(sptr_rule);
job->InternalSetRule(sptr_rule);
}
示例13: Enqueue
void JobQueue::Enqueue(InternalJob::Pointer newEntry)
{
InternalJob::Pointer tail = dummy->Next();
//overtake lower priority jobs. Only overtake conflicting jobs if allowed to
while (CanOvertake(newEntry, tail))
tail = tail->Next();
InternalJob::Pointer tailPrevious = tail->Previous();
newEntry->SetNext(tail);
newEntry->SetPrevious(tailPrevious);
tailPrevious->SetNext(newEntry);
tail->SetPrevious(newEntry);
}
示例14: AddLast
void InternalJob::AddLast(InternalJob::Pointer entry)
{
InternalJob::Pointer last;
last = this;
//find the end of the queue
while (last->previous)
last = last->previous;
//add the new entry to the end of the queue
last->previous = entry.GetPointer();
entry->next = last;
entry->previous = 0;
}
示例15: EndJob
void JobManager::EndJob(InternalJob::Pointer ptr_job, IStatus::Pointer result, bool notify)
{
Poco::Timestamp::TimeDiff rescheduleDelay(InternalJob::T_NONE);
{
Poco::ScopedLock<Poco::Mutex> lock ( m_mutex);
// if the job is finishing asynchronously, there is nothing more to do for now
if (result == Job::ASYNC_FINISH)
return;
//if job is not known then it cannot be done
if (ptr_job->GetState() == Job::NONE)
return;
ptr_job->SetResult(result);
ptr_job->SetProgressMonitor(IProgressMonitor::Pointer(nullptr));
ptr_job->SetThread(nullptr);
rescheduleDelay = ptr_job->GetStartTime().epochMicroseconds();
InternalJob::Pointer sptr_job(ptr_job);
ChangeState(sptr_job, Job::NONE);
}
//notify listeners outside sync block
bool reschedule = m_active && rescheduleDelay > InternalJob::T_NONE && ptr_job->ShouldSchedule();
if (notify)
m_JobListeners.Done(ptr_job.Cast<Job>(), result, reschedule);
//reschedule the job if requested and we are still active
if (reschedule)
Schedule(ptr_job, rescheduleDelay, reschedule);
}