launch_daemon: Maintain pending jobs for requirements.
* If a requirement cannot be launched, a job is now added to the requirement as pending job. * If the requirement enters the launch queue at a later time, the pending job will be put there, too.
This commit is contained in:
@@ -207,6 +207,27 @@ Job::AddRequirement(const char* requirement)
|
||||
}
|
||||
|
||||
|
||||
const BStringList&
|
||||
Job::Pending() const
|
||||
{
|
||||
return fPendingJobs;
|
||||
}
|
||||
|
||||
|
||||
BStringList&
|
||||
Job::Pending()
|
||||
{
|
||||
return fPendingJobs;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Job::AddPending(const char* pending)
|
||||
{
|
||||
fPendingJobs.Add(pending);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Job::CheckCondition(ConditionContext& context) const
|
||||
{
|
||||
|
||||
@@ -70,6 +70,10 @@ public:
|
||||
BStringList& Requirements();
|
||||
void AddRequirement(const char* requirement);
|
||||
|
||||
const BStringList& Pending() const;
|
||||
BStringList& Pending();
|
||||
void AddPending(const char* pending);
|
||||
|
||||
virtual bool CheckCondition(ConditionContext& context) const;
|
||||
|
||||
status_t Init(const Finder& jobs,
|
||||
@@ -137,6 +141,7 @@ private:
|
||||
mutex fLaunchStatusLock;
|
||||
::Target* fTarget;
|
||||
::Condition* fCondition;
|
||||
BStringList fPendingJobs;
|
||||
BObjectList<BMessage>
|
||||
fPendingLaunchDataReplies;
|
||||
::TeamRegistrator* fTeamRegistrator;
|
||||
|
||||
@@ -1463,6 +1463,7 @@ LaunchDaemon::_CanLaunchJobRequirements(Job* job, uint32 options)
|
||||
&& !requirement->IsRunning() && !requirement->IsLaunching()
|
||||
&& (!_CanLaunchJob(requirement, options, true)
|
||||
|| _CanLaunchJobRequirements(requirement, options))) {
|
||||
requirement->AddPending(job->Name());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1521,6 +1522,18 @@ LaunchDaemon::_LaunchJob(Job* job, uint32 options)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user