Skip to content

Commit 50fae77

Browse files
committed
feat(inc/list): add list size function
Signed-off-by: João Peixoto <[email protected]>
1 parent 02790d7 commit 50fae77

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lib/inc/list.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ static inline bool list_rm(struct list* list, node_t* node)
118118
return true;
119119
}
120120

121+
static inline size_t list_size(struct list* list)
122+
{
123+
size_t size = 0;
124+
if (list != NULL) {
125+
spin_lock(&list->lock);
126+
127+
node_t* temp = list->head;
128+
while (temp != NULL) {
129+
size++;
130+
temp = *temp;
131+
}
132+
133+
spin_unlock(&list->lock);
134+
}
135+
136+
return size;
137+
}
138+
121139
typedef int (*node_cmp_t)(node_t*, node_t*);
122140

123141
static inline void list_insert_ordered(struct list* list, node_t* node, node_cmp_t cmp)

0 commit comments

Comments
 (0)