[xutil] Add list_attach_after() and use it for cache atom

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-29 14:24:33 +02:00
parent 2a4971b725
commit eaf38a6a69
2 changed files with 11 additions and 13 deletions

View File

@ -154,9 +154,7 @@
{ \ { \
if(item->next) \ if(item->next) \
return item->next; \ return item->next; \
else \ return *list; \
return *list; \
return NULL; \
} \ } \
\ \
static inline type *prefix##_list_detach(type **list, type *item) \ static inline type *prefix##_list_detach(type **list, type *item) \
@ -170,16 +168,23 @@
item->next = NULL; \ item->next = NULL; \
item->prev = NULL; \ item->prev = NULL; \
return item; \ return item; \
} \
static inline type *prefix##_list_attach_after(type *item1, type *item2) \
{ \
item2->prev = item1; \
item2->next = item1->next; \
if(item1->next) \
item1->next->prev = item2; \
item1->next = item2; \
return item2; \
} }
#define DO_SLIST_UNREF(type, prefix, dtor) \ #define DO_SLIST_UNREF(type, prefix, dtor) \
static inline void prefix##_list_unref(type **list) \ static inline void prefix##_list_unref(type **list) \
{ \ { \
type *next, *item = *list; \ type *next, *item = *list; \
printf("list_unref\n");\
while(item) \ while(item) \
{ \ { \
printf(" item %p refcount %d", item, item->refcount);\
next = item->next; \ next = item->next; \
if(--(item->refcount) <= 0) \ if(--(item->refcount) <= 0) \
{ \ { \
@ -188,7 +193,6 @@
} \ } \
item = next; \ item = next; \
} \ } \
printf("end list_unref\n");\
} }
#endif #endif

View File

@ -233,13 +233,7 @@ xutil_intern_atom_reply(xcb_connection_t *c, xutil_atom_cache_t **atoms,
atom_next && atom_next->next && a_strcmp(atom_req.name, atom_next->next->name) > 0; atom_next && atom_next->next && a_strcmp(atom_req.name, atom_next->next->name) > 0;
atom_next = atom_cache_list_next(NULL, atom_next)); atom_next = atom_cache_list_next(NULL, atom_next));
atom_cache->prev = atom_next; atom_cache_list_attach_after(atom_next, atom_cache);
atom_cache->next = atom_next->next;
if(atom_next->next)
atom_next->next->prev = atom_cache;
atom_next->next = atom_cache;
} }
p_delete(&atom_rep); p_delete(&atom_rep);