diff --git a/include/ucore/seq.h b/include/ucore/seq.h index b53340a..72f33fb 100644 --- a/include/ucore/seq.h +++ b/include/ucore/seq.h @@ -2,19 +2,28 @@ #define SEQ_H_ #include -// Check if a is before b, taking care of wrap arounds -static inline int seq_before(uint32_t a, uint32_t b) +// Check if a is less than b, taking care of wrap arounds +static inline int uc_seq_lt(uint32_t a, uint32_t b) { return (int32_t)(a - b) < 0; } -// check if a is before b, taking care of wrap arounds -#define seq_after(a, b) before(b, a) - -//check if a is between b or c -static inline int seqbetween(uint32_t a, uint32_t b, uint32_t c) +// check if a is greather than b, taking care of wrap arounds +static inline int uc_seq_gt(uint32_t a, uint32_t b) { - return c - b >= a - b; + return (int32_t)(a - b) > 0; +} +// +// Check if a is less than or equal to b, taking care of wrap arounds +static inline int uc_seq_leq(uint32_t a, uint32_t b) +{ + return (int32_t)(a - b) <= 0; +} + +// check if a is greather than or equal b, taking care of wrap arounds +static inline int uc_seq_geq(uint32_t a, uint32_t b) +{ + return (int32_t)(a - b) >= 0; } diff --git a/test/seq.c b/test/seq.c index 7de6b0b..5750ef0 100644 --- a/test/seq.c +++ b/test/seq.c @@ -4,7 +4,7 @@ void check_before(uint32_t a, uint32_t b) { - printf("%lu before %lu = %d\n", a ,b, seq_before(a, b)); + printf("%lu before %lu = %d\n", a ,b, seq_lt(a, b)); } int main(int argc, char *argv[]) diff --git a/test/test_runner.c b/test/test_runner.c index e99966b..ea0faa2 100644 --- a/test/test_runner.c +++ b/test/test_runner.c @@ -16,6 +16,7 @@ extern Suite *logging_suite(void); extern Suite *threadqueue_suite(void); extern Suite *buffer_suite(void); extern Suite *clock_suite(void); +extern Suite *seq_suite(void); static suite_func suites[] = { bitvec_suite, @@ -28,6 +29,7 @@ static suite_func suites[] = { threadqueue_suite, buffer_suite, clock_suite, + seq_suite, }; int