Go to the documentation of this file.
23 #include <starpu_util.h>
167 #define LIST_INLINE static inline
172 #define LIST_TYPE(ENAME, DECL) \
173 LIST_CREATE_TYPE(ENAME, DECL)
175 #define LIST_CREATE_TYPE(ENAME, DECL) \
179 struct ENAME *_prev; \
180 struct ENAME *_next; \
183 LIST_CREATE_TYPE_NOSTRUCT(ENAME, _prev, _next)
187 #define LIST_CREATE_TYPE_NOSTRUCT(ENAME, _prev, _next) \
190 struct ENAME##_list \
192 struct ENAME *_head; \
193 struct ENAME *_tail; \
195 LIST_INLINE struct ENAME *ENAME##_new(void) \
196 { struct ENAME *e; _STARPU_MALLOC(e, sizeof(struct ENAME)); \
197 e->_next = NULL; e->_prev = NULL; return e; } \
198 LIST_INLINE void ENAME##_delete(struct ENAME *e) \
200 LIST_INLINE void ENAME##_list_push_front(struct ENAME##_list *l, struct ENAME *e) \
201 { if(l->_tail == NULL) l->_tail = e; else l->_head->_prev = e; \
202 e->_prev = NULL; e->_next = l->_head; l->_head = e; } \
203 LIST_INLINE void ENAME##_list_push_back(struct ENAME##_list *l, struct ENAME *e) \
204 { if(l->_head == NULL) l->_head = e; else l->_tail->_next = e; \
205 e->_next = NULL; e->_prev = l->_tail; l->_tail = e; } \
206 LIST_INLINE void ENAME##_list_insert_before(struct ENAME##_list *l, struct ENAME *e, struct ENAME *o) \
207 { struct ENAME *p = o->_prev; if (p) { p->_next = e; e->_prev = p; } else { l->_head = e; e->_prev = NULL; } \
208 e->_next = o; o->_prev = e; } \
209 LIST_INLINE void ENAME##_list_insert_after(struct ENAME##_list *l, struct ENAME *e, struct ENAME *o) \
210 { struct ENAME *n = o->_next; if (n) { n->_prev = e; e->_next = n; } else { l->_tail = e; e->_next = NULL; } \
211 e->_prev = o; o->_next = e; } \
212 LIST_INLINE void ENAME##_list_push_list_front(struct ENAME##_list *l1, struct ENAME##_list *l2) \
213 { if (l2->_head == NULL) { l2->_head = l1->_head; l2->_tail = l1->_tail; } \
214 else if (l1->_head != NULL) { l1->_tail->_next = l2->_head; l2->_head->_prev = l1->_tail; l2->_head = l1->_head; } } \
215 LIST_INLINE void ENAME##_list_push_list_back(struct ENAME##_list *l1, struct ENAME##_list *l2) \
216 { if(l1->_head == NULL) { l1->_head = l2->_head; l1->_tail = l2->_tail; } \
217 else if (l2->_head != NULL) { l1->_tail->_next = l2->_head; l2->_head->_prev = l1->_tail; l1->_tail = l2->_tail; } } \
218 LIST_INLINE struct ENAME *ENAME##_list_front(const struct ENAME##_list *l) \
219 { return l->_head; } \
220 LIST_INLINE struct ENAME *ENAME##_list_back(const struct ENAME##_list *l) \
221 { return l->_tail; } \
222 LIST_INLINE void ENAME##_list_init(struct ENAME##_list *l) \
223 { l->_head=NULL; l->_tail=l->_head; } \
224 LIST_INLINE struct ENAME##_list *ENAME##_list_new(void) \
225 { struct ENAME##_list *l; _STARPU_MALLOC(l, sizeof(struct ENAME##_list)); \
226 ENAME##_list_init(l); return l; } \
227 LIST_INLINE int ENAME##_list_empty(const struct ENAME##_list *l) \
228 { return (l->_head == NULL); } \
229 LIST_INLINE void ENAME##_list_delete(struct ENAME##_list *l) \
231 LIST_INLINE void ENAME##_list_erase(struct ENAME##_list *l, struct ENAME *c) \
232 { struct ENAME *p = c->_prev; if(p) p->_next = c->_next; else l->_head = c->_next; \
233 if(c->_next) c->_next->_prev = p; else l->_tail = p; } \
234 LIST_INLINE struct ENAME *ENAME##_list_pop_front(struct ENAME##_list *l) \
235 { struct ENAME *e = ENAME##_list_front(l); \
236 ENAME##_list_erase(l, e); return e; } \
237 LIST_INLINE struct ENAME *ENAME##_list_pop_back(struct ENAME##_list *l) \
238 { struct ENAME *e = ENAME##_list_back(l); \
239 ENAME##_list_erase(l, e); return e; } \
240 LIST_INLINE struct ENAME *ENAME##_list_begin(const struct ENAME##_list *l) \
241 { return l->_head; } \
242 LIST_INLINE struct ENAME *ENAME##_list_end(const struct ENAME##_list *l STARPU_ATTRIBUTE_UNUSED) \
244 LIST_INLINE struct ENAME *ENAME##_list_next(const struct ENAME *i) \
245 { return i->_next; } \
246 LIST_INLINE struct ENAME *ENAME##_list_last(const struct ENAME##_list *l) \
247 { return l->_tail; } \
248 LIST_INLINE struct ENAME *ENAME##_list_alpha(const struct ENAME##_list *l STARPU_ATTRIBUTE_UNUSED) \
250 LIST_INLINE struct ENAME *ENAME##_list_prev(const struct ENAME *i) \
251 { return i->_prev; } \
252 LIST_INLINE int ENAME##_list_ismember(const struct ENAME##_list *l, const struct ENAME *e) \
253 { struct ENAME *i=l->_head; while(i!=NULL){ if (i == e) return 1; i=i->_next; } return 0; } \
254 LIST_INLINE int ENAME##_list_member(const struct ENAME##_list *l, const struct ENAME *e) \
255 { struct ENAME *i=l->_head; int k=0; while(i!=NULL){if (i == e) return k; k++; i=i->_next; } return -1; } \
256 LIST_INLINE int ENAME##_list_size(const struct ENAME##_list *l) \
257 { struct ENAME *i=l->_head; int k=0; while(i!=NULL){k++;i=i->_next;} return k; } \
258 LIST_INLINE int ENAME##_list_check(const struct ENAME##_list *l) \
259 { struct ENAME *i=l->_head; while(i) \
260 { if ((i->_next == NULL) && i != l->_tail) return 0; \
261 if (i->_next == i) return 0; \
262 i=i->_next;} return 1; } \
263 LIST_INLINE void ENAME##_list_move(struct ENAME##_list *ldst, struct ENAME##_list *lsrc) \
264 { ENAME##_list_init(ldst); ldst->_head = lsrc->_head; ldst->_tail = lsrc->_tail; lsrc->_head = NULL; lsrc->_tail = NULL; }
268 #define STARPU_ASSERT_MULTILIST(expr) STARPU_ASSERT(expr)
270 #define STARPU_ASSERT_MULTILIST(expr) ((void) 0)
340 #define MULTILIST_CREATE_TYPE(ENAME, MEMBER) \
341 struct ENAME##_multilist_##MEMBER { \
342 struct ENAME##_multilist_##MEMBER *next; \
343 struct ENAME##_multilist_##MEMBER *prev; \
347 #define MULTILIST_CREATE_INLINES(TYPE, ENAME, MEMBER) \
349 LIST_INLINE TYPE *ENAME##_of_multilist_##MEMBER(struct ENAME##_multilist_##MEMBER *elt) { \
350 return ((TYPE *) ((uintptr_t) (elt) - ((uintptr_t) (&((TYPE *) 0)->MEMBER)))); \
354 LIST_INLINE void ENAME##_multilist_head_init_##MEMBER(struct ENAME##_multilist_##MEMBER *head) { \
360 LIST_INLINE void ENAME##_multilist_init_##MEMBER(TYPE *e) { \
361 (e)->MEMBER.next = NULL; \
362 (e)->MEMBER.prev = NULL; \
366 LIST_INLINE void ENAME##_multilist_push_front_##MEMBER(struct ENAME##_multilist_##MEMBER *head, TYPE *e) { \
367 STARPU_ASSERT_MULTILIST(e->MEMBER.prev == NULL); \
368 STARPU_ASSERT_MULTILIST(e->MEMBER.next == NULL); \
369 e->MEMBER.next = head->next; \
370 e->MEMBER.prev = head; \
371 head->next->prev = &e->MEMBER; \
372 head->next = &e->MEMBER; \
376 LIST_INLINE void ENAME##_multilist_push_back_##MEMBER(struct ENAME##_multilist_##MEMBER *head, TYPE *e) { \
377 STARPU_ASSERT_MULTILIST(e->MEMBER.prev == NULL); \
378 STARPU_ASSERT_MULTILIST(e->MEMBER.next == NULL); \
379 e->MEMBER.prev = head->prev; \
380 e->MEMBER.next = head; \
381 head->prev->next = &e->MEMBER; \
382 head->prev = &e->MEMBER; \
386 LIST_INLINE void ENAME##_multilist_erase_##MEMBER(struct ENAME##_multilist_##MEMBER *head STARPU_ATTRIBUTE_UNUSED, TYPE *e) { \
387 STARPU_ASSERT_MULTILIST(e->MEMBER.next->prev == &e->MEMBER); \
388 e->MEMBER.next->prev = e->MEMBER.prev; \
389 STARPU_ASSERT_MULTILIST(e->MEMBER.prev->next == &e->MEMBER); \
390 e->MEMBER.prev->next = e->MEMBER.next; \
391 e->MEMBER.next = NULL; \
392 e->MEMBER.prev = NULL; \
396 LIST_INLINE int ENAME##_multilist_queued_##MEMBER(TYPE *e) { \
397 return ((e)->MEMBER.next != NULL); \
401 LIST_INLINE int ENAME##_multilist_empty_##MEMBER(struct ENAME##_multilist_##MEMBER *head) { \
402 return head->next == head; \
406 LIST_INLINE int ENAME##_multilist_alone_##MEMBER(TYPE *e) { \
407 return (e)->MEMBER.next == (e)->MEMBER.prev; \
411 LIST_INLINE TYPE *ENAME##_multilist_begin_##MEMBER(struct ENAME##_multilist_##MEMBER *head) { \
412 return ENAME##_of_multilist_##MEMBER(head->next); \
415 LIST_INLINE TYPE *ENAME##_multilist_end_##MEMBER(struct ENAME##_multilist_##MEMBER *head) { \
416 return ENAME##_of_multilist_##MEMBER(head); \
419 LIST_INLINE TYPE *ENAME##_multilist_next_##MEMBER(TYPE *e) { \
420 return ENAME##_of_multilist_##MEMBER(e->MEMBER.next); \
424 LIST_INLINE void ENAME##_multilist_move_##MEMBER(struct ENAME##_multilist_##MEMBER *head, struct ENAME##_multilist_##MEMBER *newhead) { \
425 if (ENAME##_multilist_empty_##MEMBER(head)) \
426 ENAME##_multilist_head_init_##MEMBER(newhead); \
429 newhead->next = head->next; \
430 newhead->next->prev = newhead; \
432 head->next->prev = head->prev; \
435 newhead->prev = head->prev; \
436 newhead->prev->next = newhead; \
438 head->prev->next = head->next; \