Skip to content

Commit

Permalink
ofi_list: Add dlist_size
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Sunku <sunkusa@amazon.com>
  • Loading branch information
sunkuamzn committed Oct 10, 2023
1 parent d38ff32 commit ef073ff
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/ofi_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,23 @@ enum ofi_list_end {
struct dlist_entry {
struct dlist_entry *next;
struct dlist_entry *prev;
OFI_DBG_VAR(size_t, size);
OFI_DBG_VAR(struct dlist_entry *, list);
};

#if ENABLE_DEBUG
#define DLIST_INIT(addr) { addr, addr, 0, addr }
#else
#define DLIST_INIT(addr) { addr, addr }
#endif
#define DEFINE_LIST(name) struct dlist_entry name = DLIST_INIT(&name)

static inline void dlist_init(struct dlist_entry *head)
{
head->next = head;
head->prev = head;
OFI_DBG_SET(head->size, 0);
OFI_DBG_SET(head->list, head);
}

static inline int dlist_empty(struct dlist_entry *head)
Expand All @@ -80,6 +88,8 @@ dlist_insert_after(struct dlist_entry *item, struct dlist_entry *head)
item->prev = head;
head->next->prev = item;
head->next = item;
OFI_DBG_SET(item->list, head->list);
OFI_DBG_ADD(item->list->size, 1);
}

static inline void
Expand All @@ -95,6 +105,7 @@ static inline void dlist_remove(struct dlist_entry *item)
{
item->prev->next = item->next;
item->next->prev = item->prev;
OFI_DBG_ADD(item->list->size, -1);
}

static inline void dlist_remove_init(struct dlist_entry *item)
Expand Down Expand Up @@ -151,6 +162,13 @@ static inline void dlist_remove_init(struct dlist_entry *item)

typedef int dlist_func_t(struct dlist_entry *item, const void *arg);

#if ENABLE_DEBUG
static inline size_t dlist_size(struct dlist_entry *item)
{
return item->list->size;
}
#endif

static inline struct dlist_entry *
dlist_find_first_match(struct dlist_entry *head, dlist_func_t *match,
const void *arg)
Expand Down Expand Up @@ -214,6 +232,14 @@ static inline void dlist_splice_head(struct dlist_entry *head,
head->next = to_splice->next;
head->next->prev = head;

OFI_DBG_ADD(head->size, to_splice->size);
#if ENABLE_DEBUG
struct dlist_entry *item;
dlist_foreach(to_splice, item) {
item->list = head->list;
}
#endif

/* set list to empty */
dlist_init(to_splice);
}
Expand Down

0 comments on commit ef073ff

Please sign in to comment.