From ad9021545269d3f6807824abc6766226af4b2405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sat, 30 Nov 2013 03:24:43 +0100 Subject: [PATCH] Add UC_TAILQ_CONTAINER. Fix spelling error --- include/ucore/tailq.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/ucore/tailq.h b/include/ucore/tailq.h index f8e82f4..a890b93 100644 --- a/include/ucore/tailq.h +++ b/include/ucore/tailq.h @@ -2,8 +2,7 @@ #define UC_TAILQ_H_ #ifdef __GNUC__ -//#define UC_INLINE __attribute__((always_inline,flatten)) -#define UC_INLINE inline +#define UC_INLINE inline __attribute__((always_inline,flatten)) #else #define UC_INLINE inline #endif @@ -43,6 +42,15 @@ struct TailQ { #define UC_TAILQ_HEAD(name)\ struct TailQ name = UC_TAILQ_HEAD_INIT(name) +//given 'ptr' as a pointer to a struct 'member', +//find the struct that ptr is the member of, where +//'type' is the type of the containing struct +//This is basically UC_CONTAINER_OF in ucore/utils.h, this is here +//to make tailq.h a standalone header +#define UC_TAILQ_CONTAINER(ptr, type, member) ({\ +typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)((void *)(unsigned char *)__mptr - offsetof(type, member) ); }) + static UC_INLINE void uc_tailq_init(struct TailQ *head) { @@ -112,7 +120,7 @@ static UC_INLINE void uc_tailq_remove(struct TailQ *entry) static UC_INLINE void uc_tailq_move_head(struct TailQ *entry, struct TailQ *head) { uc_tailq_link(entry->prev, entry->next); - uc_taiq_insert(entry, head, head->next); + uc_tailq_insert(entry, head, head->next); } /** Move entry from its current tailq to the tail of another tailq. @@ -121,7 +129,7 @@ static UC_INLINE void uc_tailq_move_head(struct TailQ *entry, struct TailQ *head static UC_INLINE void uc_tailq_move_tail(struct TailQ *entry, struct TailQ *head) { uc_tailq_link(entry->prev, entry->next); - uc_taiq_insert(entry, head->prev, head); + uc_tailq_insert(entry, head->prev, head); } //FIRST/NEXT/LAST/PREV macros similar to sys/queue.h