#ifndef _TIMETABLEQ_H_ #define _TIMETABLEQ_H_ #include #define TIMETABLEQ_HEAD(name, type, ntable) \ struct name { \ int tth_ntimetable; \ int tth_timeindexbase; \ LIST_HEAD(, type) tth_timetable[ntable]; \ } #define TIMETABLEQ_ENTRY(type) \ LIST_ENTRY(type) #define TIMETABLEQ_INIT(head, ntable) do { \ int i; \ (head)->tth_ntimetable = ntable; \ (head)->tth_timeindexbase = 0; \ for (i = 0; i < ntable; i++) { \ LIST_INIT(&((head)->tth_timetable[i])); \ } \ } while (/*CONSTCOND*/0) #define TIMETABLEQ_INSERT_AFTER(listelm, elm, field) \ LIST_INSERT_AFTER(listelm, elm, field) #define TIMETABLEQ_INSERT_BEFORE(listelm, elm, field) \ LIST_INSERT_BEFORE(listelm, elm, field) #define TIMETABLEQ_INSERT_HEAD(head, nth_table, elm, field) do { \ int idx; \ idx = nth_table; \ \ if (idx < 0) \ idx = 0; \ if (idx >= (head)->tth_ntimetable) \ idx = (head)->tth_ntimetable - 1; \ \ idx += (head)->tth_timeindexbase; \ idx %= (head)->tth_ntimetable; \ \ LIST_INSERT_HEAD(&((head)->tth_timetable[idx]), elm, field); \ } while (/*CONSTCOND*/0) #define TIMETABLEQ_REMOVE(elm, field) \ LIST_REMOVE(elm, field) #define TIMETABLEQ_EMPTY_TABLE(head, nth_table) \ LIST_EMPTY(&((head)->tth_timetable[((head)->tth_timeindexbase + \ nth_table) % (head)->tth_ntimetable])) #define TIMETABLEQ_FIRST_TABLE(head, nth_table) \ LIST_FIRST(&((head)->tth_timetable[((head)->tth_timeindexbase + \ nth_table) % (head)->tth_ntimetable])) #define TIMETABLEQ_NEXT(elm, field) \ LIST_NEXT(elm, field) #define TIMETABLEQ_FOREACH_TABLE(var, head, nth_table, field) \ LIST_FOREACH(var, \ &((head)->tth_timetable[((head)->tth_timeindexbase + \ nth_table) % (head)->tth_ntimetable]), field) #define TIMETABLEQ_ROTATE(head) do { \ (head)->tth_timeindexbase = \ ((head)->tth_timeindexbase + 1) % (head)->tth_ntimetable; \ } while (/*CONSTCOND*/0) #define TIMETABLEQ_DUMP(head, type, field) do { \ int i; \ \ printf("[%p]\n", head); \ printf(" tth_ntimetable = %d\n", (head)->tth_ntimetable); \ printf(" tth_timeindexbase = %d\n", (head)->tth_timeindexbase); \ \ for (i = 0; i < (head)->tth_ntimetable; i++) { \ struct type *p; \ int idx = ((head)->tth_timeindexbase + i) % \ (head)->tth_ntimetable; \ \ printf(" tth_timetable[%d]:", idx); \ LIST_FOREACH(p, &((head)->tth_timetable[idx]), field) { \ printf("<%p>", p); \ } \ printf("\n"); \ } \ } while (/*CONSTCOND*/0) #endif /* _TIMETABLEQ_H_ */