Skip to content

Commit 3c895f3

Browse files
committed
CLEANUP: lists/tree-wide: rename some list operations to avoid some confusion
The current "ADD" vs "ADDQ" is confusing because when thinking in terms of appending at the end of a list, "ADD" naturally comes to mind, but here it does the opposite, it inserts. Several times already it's been incorrectly used where ADDQ was expected, the latest of which was a fortunate accident explained in 6fa922562 ("CLEANUP: stream: explain why we queue the stream at the head of the server list"). Let's use more explicit (but slightly longer) names now: LIST_ADD -> LIST_INSERT LIST_ADDQ -> LIST_APPEND LIST_ADDED -> LIST_INLIST LIST_DEL -> LIST_DELETE The same is true for MT_LISTs, including their "TRY" variant. LIST_DEL_INIT keeps its short name to encourage to use it instead of the lazier LIST_DELETE which is often less safe. The change is large (~674 non-comment entries) but is mechanical enough to remain safe. No permutation was performed, so any out-of-tree code can easily map older names to new ones. The list doc was updated.
1 parent 1643f7d commit 3c895f3

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

include/haproxy/list.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
#define LIST_HEAD_INIT(l) { &l, &l }
4545

4646
/* adds an element at the beginning of a list ; returns the element */
47-
#define LIST_ADD(lh, el) ({ (el)->n = (lh)->n; (el)->n->p = (lh)->n = (el); (el)->p = (lh); (el); })
47+
#define LIST_INSERT(lh, el) ({ (el)->n = (lh)->n; (el)->n->p = (lh)->n = (el); (el)->p = (lh); (el); })
4848

4949
/* adds an element at the end of a list ; returns the element */
50-
#define LIST_ADDQ(lh, el) ({ (el)->p = (lh)->p; (el)->p->n = (lh)->p = (el); (el)->n = (lh); (el); })
50+
#define LIST_APPEND(lh, el) ({ (el)->p = (lh)->p; (el)->p->n = (lh)->p = (el); (el)->n = (lh); (el); })
5151

5252
/* adds the contents of a list <old> at the beginning of another list <new>. The old list head remains untouched. */
5353
#define LIST_SPLICE(new, old) do { \
@@ -71,10 +71,10 @@
7171
} while (0)
7272

7373
/* removes an element from a list and returns it */
74-
#define LIST_DEL(el) ({ typeof(el) __ret = (el); (el)->n->p = (el)->p; (el)->p->n = (el)->n; (__ret); })
74+
#define LIST_DELETE(el) ({ typeof(el) __ret = (el); (el)->n->p = (el)->p; (el)->p->n = (el)->n; (__ret); })
7575

7676
/* removes an element from a list, initializes it and returns it.
77-
* This is faster than LIST_DEL+LIST_INIT as we avoid reloading the pointers.
77+
* This is faster than LIST_DELETE+LIST_INIT as we avoid reloading the pointers.
7878
*/
7979
#define LIST_DEL_INIT(el) ({ \
8080
typeof(el) __ret = (el); \
@@ -98,7 +98,7 @@
9898
/* checks if the list element <el> was added to a list or not. This only
9999
* works when detached elements are reinitialized (using LIST_DEL_INIT)
100100
*/
101-
#define LIST_ADDED(el) ((el)->n != (el))
101+
#define LIST_INLIST(el) ((el)->n != (el))
102102

103103
/* returns a pointer of type <pt> to a structure following the element
104104
* which contains list head <lh>, which is known as element <el> in
@@ -224,7 +224,7 @@
224224
* Returns 1 if we added the item, 0 otherwise (because it was already in a
225225
* list).
226226
*/
227-
#define MT_LIST_TRY_ADD(_lh, _el) \
227+
#define MT_LIST_TRY_INSERT(_lh, _el) \
228228
({ \
229229
int _ret = 0; \
230230
struct mt_list *lh = (_lh), *el = (_el); \
@@ -283,7 +283,7 @@
283283
* Returns 1 if we added the item, 0 otherwise (because it was already in a
284284
* list).
285285
*/
286-
#define MT_LIST_TRY_ADDQ(_lh, _el) \
286+
#define MT_LIST_TRY_APPEND(_lh, _el) \
287287
({ \
288288
int _ret = 0; \
289289
struct mt_list *lh = (_lh), *el = (_el); \
@@ -341,7 +341,7 @@
341341
* Add an item at the beginning of a list.
342342
* It is assumed the element can't already be in a list, so it isn't checked.
343343
*/
344-
#define MT_LIST_ADD(_lh, _el) \
344+
#define MT_LIST_INSERT(_lh, _el) \
345345
({ \
346346
int _ret = 0; \
347347
struct mt_list *lh = (_lh), *el = (_el); \
@@ -374,7 +374,7 @@
374374
* Add an item at the end of a list.
375375
* It is assumed the element can't already be in a list, so it isn't checked
376376
*/
377-
#define MT_LIST_ADDQ(_lh, _el) \
377+
#define MT_LIST_APPEND(_lh, _el) \
378378
({ \
379379
int _ret = 0; \
380380
struct mt_list *lh = (_lh), *el = (_el); \
@@ -406,8 +406,8 @@
406406
/*
407407
* Detach a list from its head. A pointer to the first element is returned
408408
* and the list is closed. If the list was empty, NULL is returned. This may
409-
* exclusively be used with lists modified by MT_LIST_TRY_ADD/MT_LIST_TRY_ADDQ. This
410-
* is incompatible with MT_LIST_DEL run concurrently.
409+
* exclusively be used with lists modified by MT_LIST_TRY_INSERT/MT_LIST_TRY_APPEND. This
410+
* is incompatible with MT_LIST_DELETE run concurrently.
411411
* If there's at least one element, the next of the last element will always
412412
* be NULL.
413413
*/
@@ -454,7 +454,7 @@
454454
/* Remove an item from a list.
455455
* Returns 1 if we removed the item, 0 otherwise (because it was in no list).
456456
*/
457-
#define MT_LIST_DEL(_el) \
457+
#define MT_LIST_DELETE(_el) \
458458
({ \
459459
int _ret = 0; \
460460
struct mt_list *el = (_el); \
@@ -589,7 +589,7 @@
589589
/* checks if the list element <el> was added to a list or not. This only
590590
* works when detached elements are reinitialized (using LIST_DEL_INIT)
591591
*/
592-
#define MT_LIST_ADDED(el) ((el)->next != (el))
592+
#define MT_LIST_INLIST(el) ((el)->next != (el))
593593

594594
/* Lock an element in the list, to be sure it won't be removed.
595595
* It needs to be synchronized somehow to be sure it's not removed
@@ -722,19 +722,19 @@
722722
p->next = n; \
723723
} while (0);
724724

725-
/* Equivalent of MT_LIST_DEL(), to be used when parsing the list with mt_list_entry_for_each_safe().
725+
/* Equivalent of MT_LIST_DELETE(), to be used when parsing the list with mt_list_entry_for_each_safe().
726726
* It should be the element currently parsed (tmpelt1)
727727
*/
728-
#define MT_LIST_DEL_SAFE(_el) \
728+
#define MT_LIST_DELETE_SAFE(_el) \
729729
do { \
730730
struct mt_list *el = (_el); \
731731
(el)->prev = (el); \
732732
(el)->next = (el); \
733733
(_el) = NULL; \
734734
} while (0)
735735

736-
/* Safe as MT_LIST_DEL_SAFE, but it won't reinit the element */
737-
#define MT_LIST_DEL_SAFE_NOINIT(_el) \
736+
/* Safe as MT_LIST_DELETE_SAFE, but it won't reinit the element */
737+
#define MT_LIST_DELETE_SAFE_NOINIT(_el) \
738738
do { \
739739
(_el) = NULL; \
740740
} while (0)
@@ -745,10 +745,10 @@
745745
* the list is passed in <list_head>. A temporary variable <back> of same type
746746
* as <item> is needed so that <item> may safely be deleted if needed.
747747
* tmpelt1 is a temporary struct mt_list *, and tmpelt2 is a temporary
748-
* struct mt_list, used internally, both are needed for MT_LIST_DEL_SAFE.
748+
* struct mt_list, used internally, both are needed for MT_LIST_DELETE_SAFE.
749749
* Example: list_for_each_entry_safe(cur_acl, tmp, known_acl, list, elt1, elt2)
750750
* { ... };
751-
* If you want to remove the current element, please use MT_LIST_DEL_SAFE.
751+
* If you want to remove the current element, please use MT_LIST_DELETE_SAFE.
752752
*/
753753
#define mt_list_for_each_entry_safe(item, list_head, member, tmpelt, tmpelt2) \
754754
for ((tmpelt) = NULL; (tmpelt) != MT_LIST_BUSY; ({ \

spoa.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,11 @@ release_frame(struct spoe_frame *frame)
972972
event_del(&frame->process_frame_event);
973973

974974
worker = frame->worker;
975-
LIST_DEL(&frame->list);
975+
LIST_DELETE(&frame->list);
976976
if (frame->frag_buf)
977977
free(frame->frag_buf);
978978
memset(frame, 0, sizeof(*frame)+max_frame_size+4);
979-
LIST_ADDQ(&worker->frames, &frame->list);
979+
LIST_APPEND(&worker->frames, &frame->list);
980980
}
981981

982982
static void
@@ -989,7 +989,7 @@ release_client(struct client *c)
989989

990990
DEBUG(c->worker, "<%lu> Release client", c->id);
991991

992-
LIST_DEL(&c->by_worker);
992+
LIST_DELETE(&c->by_worker);
993993
c->worker->nbclients--;
994994

995995
unuse_spoe_engine(c);
@@ -1061,12 +1061,12 @@ use_spoe_engine(struct client *client)
10611061
LIST_INIT(&eng->clients);
10621062
LIST_INIT(&eng->processing_frames);
10631063
LIST_INIT(&eng->outgoing_frames);
1064-
LIST_ADDQ(&client->worker->engines, &eng->list);
1064+
LIST_APPEND(&client->worker->engines, &eng->list);
10651065
LOG(client->worker, "Add new SPOE engine '%s'", eng->id);
10661066

10671067
end:
10681068
client->engine = eng;
1069-
LIST_ADDQ(&eng->clients, &client->by_engine);
1069+
LIST_APPEND(&eng->clients, &client->by_engine);
10701070
}
10711071

10721072
static void
@@ -1080,12 +1080,12 @@ unuse_spoe_engine(struct client *client)
10801080

10811081
eng = client->engine;
10821082
client->engine = NULL;
1083-
LIST_DEL(&client->by_engine);
1083+
LIST_DELETE(&client->by_engine);
10841084
if (!LIST_ISEMPTY(&eng->clients))
10851085
return;
10861086

10871087
LOG(client->worker, "Remove SPOE engine '%s'", eng->id);
1088-
LIST_DEL(&eng->list);
1088+
LIST_DELETE(&eng->list);
10891089

10901090
list_for_each_entry_safe(frame, back, &eng->processing_frames, list) {
10911091
release_frame(frame);
@@ -1115,7 +1115,7 @@ acquire_incoming_frame(struct client *client)
11151115
}
11161116
else {
11171117
frame = LIST_NEXT(&client->worker->frames, typeof(frame), list);
1118-
LIST_DEL(&frame->list);
1118+
LIST_DELETE(&frame->list);
11191119
}
11201120

11211121
reset_frame(frame);
@@ -1143,12 +1143,12 @@ acquire_outgoing_frame(struct client *client)
11431143
frame = client->outgoing_frame;
11441144
else if (!LIST_ISEMPTY(&client->outgoing_frames)) {
11451145
frame = LIST_NEXT(&client->outgoing_frames, typeof(frame), list);
1146-
LIST_DEL(&frame->list);
1146+
LIST_DELETE(&frame->list);
11471147
client->outgoing_frame = frame;
11481148
}
11491149
else if (engine!= NULL && !LIST_ISEMPTY(&engine->outgoing_frames)) {
11501150
frame = LIST_NEXT(&engine->outgoing_frames, typeof(frame), list);
1151-
LIST_DEL(&frame->list);
1151+
LIST_DELETE(&frame->list);
11521152
client->outgoing_frame = frame;
11531153
}
11541154
return frame;
@@ -1159,7 +1159,7 @@ write_frame(struct client *client, struct spoe_frame *frame)
11591159
{
11601160
uint32_t netint;
11611161

1162-
LIST_DEL(&frame->list);
1162+
LIST_DELETE(&frame->list);
11631163

11641164
frame->buf = (char *)(frame->data);
11651165
frame->offset = 0;
@@ -1175,7 +1175,7 @@ write_frame(struct client *client, struct spoe_frame *frame)
11751175
if (client->outgoing_frame == NULL)
11761176
client->outgoing_frame = frame;
11771177
else
1178-
LIST_ADD(&client->outgoing_frames, &frame->list);
1178+
LIST_INSERT(&client->outgoing_frames, &frame->list);
11791179
}
11801180
else {
11811181
client->outgoing_frame = frame;
@@ -1184,12 +1184,12 @@ write_frame(struct client *client, struct spoe_frame *frame)
11841184
}
11851185
else { /* for all other frames */
11861186
if (frame->client == NULL) { /* async mode ! */
1187-
LIST_ADDQ(&frame->engine->outgoing_frames, &frame->list);
1187+
LIST_APPEND(&frame->engine->outgoing_frames, &frame->list);
11881188
list_for_each_entry(client, &frame->engine->clients, by_engine)
11891189
event_add(&client->write_frame_event, NULL);
11901190
}
11911191
else if (frame->client->pipelining) {
1192-
LIST_ADDQ(&frame->client->outgoing_frames, &frame->list);
1192+
LIST_APPEND(&frame->client->outgoing_frames, &frame->list);
11931193
event_add(&frame->client->write_frame_event, NULL);
11941194
}
11951195
else {
@@ -1213,10 +1213,10 @@ process_incoming_frame(struct spoe_frame *frame)
12131213

12141214
if (client->async) {
12151215
frame->client = NULL;
1216-
LIST_ADDQ(&frame->engine->processing_frames, &frame->list);
1216+
LIST_APPEND(&frame->engine->processing_frames, &frame->list);
12171217
}
12181218
else if (client->pipelining)
1219-
LIST_ADDQ(&client->processing_frames, &frame->list);
1219+
LIST_APPEND(&client->processing_frames, &frame->list);
12201220
else
12211221
event_del(&client->read_frame_event);
12221222
}
@@ -1632,7 +1632,7 @@ accept_cb(int listener, short event, void *arg)
16321632
LIST_INIT(&client->processing_frames);
16331633
LIST_INIT(&client->outgoing_frames);
16341634

1635-
LIST_ADDQ(&worker->clients, &client->by_worker);
1635+
LIST_APPEND(&worker->clients, &client->by_worker);
16361636

16371637
worker->nbclients++;
16381638

@@ -1662,7 +1662,7 @@ worker_function(void *data)
16621662
}
16631663

16641664
list_for_each_entry_safe(frame, fback, &worker->frames, list) {
1665-
LIST_DEL(&frame->list);
1665+
LIST_DELETE(&frame->list);
16661666
free(frame);
16671667
}
16681668

0 commit comments

Comments
 (0)