diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2012-04-05 08:34:05 +0200 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2012-04-05 11:54:13 +0200 |
commit | 348e27fedfd4cdd2238ff31a46785a70b9dc6fc0 (patch) | |
tree | d6f22a9c3fd626aaa5605d41d59a424d8b91a36d /src/job.h | |
parent | b8217b7bd5fd171916a095b150fad4c3a37f5a41 (diff) |
job: use a lookup table for merging of job types
It is easier to see what job_type_merge() is doing when the merging
rules are written in the form of a table.
job_type_is_superset() contained redundant information. It can be
simplified to a simple rule: Type A is a superset of B iff merging A
with B gives A.
Two job types are conflicting iff they are not mergeable.
Make job_type_lookup_merge() the core function to decide the type
merging. All other job_type_*() are just short wrappers around it.
They can be inline.
test-job-type gives the same results as before.
btw, the systemd binary is smaller by almost 1 KB.
Diffstat (limited to 'src/job.h')
-rw-r--r-- | src/job.h | 29 |
1 files changed, 25 insertions, 4 deletions
@@ -24,6 +24,7 @@ #include <stdbool.h> #include <inttypes.h> +#include <errno.h> 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); |