mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-17 02:56:51 +00:00
MINOR: mt_lists: Give MT_LIST_ADD, MT_LIST_ADDQ and MT_LIST_DEL a return value.
Make it so MT_LIST_ADD and MT_LIST_ADDQ return 1 if it managed to add the item, 0 (because it was already in a list) otherwise. Make it so MT_LIST_DEL returns 1 if it managed to remove the item from a list, or 0 otherwise (because it was in no list).
This commit is contained in:
parent
cb22ad4f71
commit
0cd6a976ff
@ -204,10 +204,17 @@ struct cond_wordlist {
|
|||||||
/*
|
/*
|
||||||
* Locked version of list manipulation macros.
|
* Locked version of list manipulation macros.
|
||||||
* It is OK to use those concurrently from multiple threads, as long as the
|
* It is OK to use those concurrently from multiple threads, as long as the
|
||||||
* list is only used with the locked variants. The only "unlocked" macro you
|
* list is only used with the locked variants.
|
||||||
* can use with a locked list is LIST_INIT.
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an item at the beginning of a list.
|
||||||
|
* Returns 1 if we added the item, 0 otherwise (because it was already in a
|
||||||
|
* list).
|
||||||
*/
|
*/
|
||||||
#define MT_LIST_ADD(lh, el) \
|
#define MT_LIST_ADD(lh, el) \
|
||||||
|
({ \
|
||||||
|
int _ret = 0; \
|
||||||
do { \
|
do { \
|
||||||
while (1) { \
|
while (1) { \
|
||||||
struct mt_list *n; \
|
struct mt_list *n; \
|
||||||
@ -233,11 +240,21 @@ struct cond_wordlist {
|
|||||||
__ha_barrier_store(); \
|
__ha_barrier_store(); \
|
||||||
p->next = (el); \
|
p->next = (el); \
|
||||||
__ha_barrier_store(); \
|
__ha_barrier_store(); \
|
||||||
|
_ret = 1; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0); \
|
||||||
|
(_ret); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an item at the end of a list.
|
||||||
|
* Returns 1 if we added the item, 0 otherwise (because it was already in a
|
||||||
|
* list).
|
||||||
|
*/
|
||||||
#define MT_LIST_ADDQ(lh, el) \
|
#define MT_LIST_ADDQ(lh, el) \
|
||||||
|
({ \
|
||||||
|
int _ret = 0; \
|
||||||
do { \
|
do { \
|
||||||
while (1) { \
|
while (1) { \
|
||||||
struct mt_list *n; \
|
struct mt_list *n; \
|
||||||
@ -263,11 +280,19 @@ struct cond_wordlist {
|
|||||||
__ha_barrier_store(); \
|
__ha_barrier_store(); \
|
||||||
n->prev = (el); \
|
n->prev = (el); \
|
||||||
__ha_barrier_store(); \
|
__ha_barrier_store(); \
|
||||||
|
_ret = 1; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0); \
|
||||||
|
(_ret); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Remove an item from a list.
|
||||||
|
* Returns 1 if we removed the item, 0 otherwise (because it was in no list).
|
||||||
|
*/
|
||||||
#define MT_LIST_DEL(el) \
|
#define MT_LIST_DEL(el) \
|
||||||
|
({ \
|
||||||
|
int _ret = 0; \
|
||||||
do { \
|
do { \
|
||||||
while (1) { \
|
while (1) { \
|
||||||
struct mt_list *n, *n2; \
|
struct mt_list *n, *n2; \
|
||||||
@ -303,13 +328,17 @@ struct cond_wordlist {
|
|||||||
} \
|
} \
|
||||||
n->prev = p; \
|
n->prev = p; \
|
||||||
p->next = n; \
|
p->next = n; \
|
||||||
|
if (p != (el) && n != (el)) \
|
||||||
|
_ret = 1; \
|
||||||
__ha_barrier_store(); \
|
__ha_barrier_store(); \
|
||||||
(el)->prev = (el); \
|
(el)->prev = (el); \
|
||||||
(el)->next = (el); \
|
(el)->next = (el); \
|
||||||
__ha_barrier_store(); \
|
__ha_barrier_store(); \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0); \
|
||||||
|
(_ret); \
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
/* Remove the first element from the list, and return it */
|
/* Remove the first element from the list, and return it */
|
||||||
|
Loading…
Reference in New Issue
Block a user