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:
Axel Dörfler
2015-11-28 14:00:36 +01:00
parent 236e68efdc
commit 59e6d9d2e2
3 changed files with 39 additions and 0 deletions
+21
View File
@@ -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
{
+5
View File
@@ -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;
+13
View File
@@ -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;
}