From 1b3864fc472ed82ad35625c8d950d0711a8aa3d6 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Wed, 30 Jul 2014 13:25:19 +0200 Subject: tbf: Use plain old data structure (PODS) for llist management The PODS struct has a back pointer to access the actual object. llist_pods_for_each_entry traverses the list of struct llist_pods and makes the entry available (through the back pointer). Ticket: SYS#389 Sponsored-by: On-Waves ehf --- src/tbf.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/tbf.h') diff --git a/src/tbf.h b/src/tbf.h index 4d209879..95355bd6 100644 --- a/src/tbf.h +++ b/src/tbf.h @@ -84,6 +84,28 @@ enum gprs_rlcmac_tbf_direction { #define GPRS_RLCMAC_FLAG_TO_DL_ASS 7 #define GPRS_RLCMAC_FLAG_TO_MASK 0xf0 /* timeout bits */ +struct llist_pods { + struct llist_head list; + void *back; +}; + +#define llist_pods_entry(ptr, type) \ + ((type *)(container_of(ptr, struct llist_pods, list)->back)) + +/** + * llist_pods_for_each_entry - like llist_for_each_entry, but uses + * struct llist_pods ->back to access the entry. + * This is necessary for non-PODS classes because container_of is + * not guaranteed to work anymore. */ +#define llist_pods_for_each_entry(pos, head, member, lpods) \ + for (lpods = llist_entry((head)->next, typeof(struct llist_pods), list), \ + pos = ((typeof(pos))lpods->back), \ + prefetch(pos->member.list.next); \ + &lpods->list != (head); \ + lpods = llist_entry(lpods->list.next, typeof(struct llist_pods), list), \ + pos = ((typeof(pos))lpods->back),\ + prefetch(pos->member.list.next)) + struct gprs_rlcmac_tbf { static void free_all(struct gprs_rlcmac_trx *trx); @@ -143,7 +165,7 @@ struct gprs_rlcmac_tbf { /* attempt to make things a bit more fair */ void rotate_in_list(); - struct llist_head list; + struct llist_pods list; uint32_t state_flags; enum gprs_rlcmac_tbf_direction direction; struct gprs_rlcmac_trx *trx; -- cgit v1.2.3