X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjob.h;h=60a43e074d4e52ea916a5891658f343bf4199dfb;hb=b8b5e648cacc8d73c55fdffbb3466ecd8146131a;hp=2121426b33313627440a6952503267f13e248d82;hpb=cebe0d41e4d5b3fdd9d521116cc029bcb819c90d;p=elogind.git diff --git a/src/job.h b/src/job.h index 2121426b3..60a43e074 100644 --- a/src/job.h +++ b/src/job.h @@ -24,6 +24,7 @@ #include #include +#include typedef struct Job Job; typedef struct JobDependency JobDependency; @@ -37,6 +38,7 @@ typedef enum JobResult JobResult; #include "hashmap.h" #include "list.h" +/* Be careful when changing the job types! Adjust job_merging_table[] accordingly! */ enum JobType { JOB_START, /* if a unit does not support being started, we'll just wait until it becomes active */ JOB_VERIFY_ACTIVE, @@ -145,10 +147,29 @@ bool job_is_anchor(Job *j); int job_merge(Job *j, Job *other); -int job_type_merge(JobType *a, JobType b); -bool job_type_is_mergeable(JobType a, JobType b); -bool job_type_is_superset(JobType a, JobType b); -bool job_type_is_conflicting(JobType a, JobType b); +JobType job_type_lookup_merge(JobType a, JobType b); + +static inline int job_type_merge(JobType *a, JobType b) { + JobType t = job_type_lookup_merge(*a, b); + if (t < 0) + return -EEXIST; + *a = t; + return 0; +} + +static inline bool job_type_is_mergeable(JobType a, JobType b) { + return job_type_lookup_merge(a, b) >= 0; +} + +static inline bool job_type_is_conflicting(JobType a, JobType b) { + return !job_type_is_mergeable(a, b); +} + +static inline bool job_type_is_superset(JobType a, JobType b) { + /* Checks whether operation a is a "superset" of b in its actions */ + return a == job_type_lookup_merge(a, b); +} + bool job_type_is_redundant(JobType a, UnitActiveState b); bool job_is_runnable(Job *j);