diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2017-01-17 14:11:31 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-01-17 14:27:06 +0100 |
commit | a1351738ba11c8e2d38f6df5276cc59f7acb2d2f (patch) | |
tree | fdcc605e39a4ddec3d42921241f6d03ec461cf59 | |
parent | 80e70fdcf8861ab757b6bfc8f0fbaec31cde57bf (diff) |
list: Remove cds_list_* wrappers
Use the cds_list_* types and macros directly instead of redefining them.
This makes it clear that we're not using the Linux kernel implementation
of list_head but the one from urcu.
Also make sure _LGPL_SOURCE is defined everywhere the urcu
functionality is used, such that we get the statically linkable version
with reduced overhead.
Reference: https://lwn.net/Articles/573424/#qq2answer
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | flowtop.c | 28 | ||||
-rw-r--r-- | list.h | 39 | ||||
-rw-r--r-- | ui.c | 13 | ||||
-rw-r--r-- | ui.h | 8 |
4 files changed, 26 insertions, 62 deletions
@@ -19,13 +19,16 @@ #include <curses.h> #include <sys/time.h> #include <sys/fsuid.h> -#include <urcu.h> #include <libgen.h> #include <inttypes.h> #include <poll.h> #include <fcntl.h> #include <arpa/inet.h> +#include <urcu.h> +#include <urcu/list.h> +#include <urcu/rculist.h> + #include "ui.h" #include "die.h" #include "xmalloc.h" @@ -50,7 +53,7 @@ #endif struct flow_entry { - struct list_head entry; + struct cds_list_head entry; struct rcu_head rcu; uint32_t flow_id, use, status; @@ -79,7 +82,7 @@ struct flow_entry { }; struct flow_list { - struct list_head head; + struct cds_list_head head; }; enum flow_direction { @@ -369,7 +372,7 @@ static void flow_entry_xfree_rcu(struct rcu_head *head) static inline void flow_list_init(struct flow_list *fl) { - INIT_LIST_HEAD(&fl->head); + CDS_INIT_LIST_HEAD(&fl->head); } static inline bool nfct_is_dns(const struct nf_conntrack *ct) @@ -398,7 +401,7 @@ static int flow_list_new_entry(struct flow_list *fl, struct nf_conntrack *ct) flow_entry_from_ct(n, ct); flow_entry_get_extended(n); - list_add_rcu(&n->entry, &fl->head); + cds_list_add_rcu(&n->entry, &fl->head); n->is_visible = true; @@ -409,7 +412,7 @@ static struct flow_entry *flow_list_find_id(struct flow_list *fl, uint32_t id) { struct flow_entry *n; - list_for_each_entry_rcu(n, &fl->head, entry) { + cds_list_for_each_entry_rcu(n, &fl->head, entry) { if (n->flow_id == id) return n; } @@ -423,7 +426,7 @@ static int flow_list_del_entry(struct flow_list *fl, const struct nf_conntrack * n = flow_list_find_id(fl, nfct_get_attr_u32(ct, ATTR_ID)); if (n) { - list_del_rcu(&n->entry); + cds_list_del_rcu(&n->entry); call_rcu(&n->rcu, flow_entry_xfree_rcu); } @@ -434,8 +437,8 @@ static void flow_list_destroy(struct flow_list *fl) { struct flow_entry *n, *tmp; - list_for_each_entry_safe(n, tmp, &fl->head, entry) { - list_del_rcu(&n->entry); + cds_list_for_each_entry_safe(n, tmp, &fl->head, entry) { + cds_list_del_rcu(&n->entry); call_rcu(&n->rcu, flow_entry_xfree_rcu); } } @@ -1012,14 +1015,14 @@ static void draw_flows(WINDOW *screen, struct flow_list *fl, rcu_read_lock(); - if (list_empty(&fl->head)) + if (cds_list_empty(&fl->head)) mvwprintw(screen, line, 2, "(No sessions! " "Is netfilter running?)"); ui_table_clear(&flows_tbl); ui_table_header_print(&flows_tbl); - list_for_each_entry_rcu(n, &fl->head, entry) { + cds_list_for_each_entry_rcu(n, &fl->head, entry) { if (!n->is_visible) continue; if (presenter_flow_wrong_state(n)) @@ -1398,8 +1401,9 @@ static void collector_refresh_flows(struct nfct_handle *handle) { struct flow_entry *n; - list_for_each_entry_rcu(n, &flow_list.head, entry) + cds_list_for_each_entry_rcu(n, &flow_list.head, entry) { nfct_query(handle, NFCT_Q_GET, n->ct); + } } static void collector_create_filter(struct nfct_handle *nfct) @@ -1,39 +0,0 @@ -#ifndef LIST_I_H -#define LIST_I_H - -#include <urcu/list.h> -#include <urcu/rculist.h> - -#define list_head cds_list_head - -#define LIST_HEAD CDS_LIST_HEAD -#define INIT_LIST_HEAD CDS_INIT_LIST_HEAD -#define LIST_HEAD_INIT CDS_LIST_HEAD_INIT - -#define list_add cds_list_add -#define list_add_tail cds_list_add_tail -#define list_del cds_list_del -#define list_del_init cds_list_del_init -#define list_move cds_list_move -#define list_replace cds_list_replace -#define list_splice cds_list_splice -#define list_entry cds_list_entry -#define list_first_entry cds_list_first_entry -#define list_for_each cds_list_for_each -#define list_for_each_safe cds_list_for_each_safe -#define list_for_each_prev cds_list_for_each_prev -#define list_for_each_prev_safe cds_list_for_each_prev_safe -#define list_for_each_entry cds_list_for_each_entry -#define list_for_each_entry_safe cds_list_for_each_entry_safe -#define list_for_each_entry_reverse cds_list_for_each_entry_reverse -#define list_empty cds_list_empty -#define list_replace_init cds_list_replace_init - -#define list_add_rcu cds_list_add_rcu -#define list_add_tail_rcu cds_list_add_tail_rcu -#define list_replace_rcu cds_list_replace_rcu -#define list_del_rcu cds_list_del_rcu -#define list_for_each_rcu cds_list_for_each_rcu -#define list_for_each_entry_rcu cds_list_for_each_entry_rcu - -#endif /* LIST_I_H */ @@ -63,14 +63,14 @@ void ui_table_init(struct ui_table *tbl) tbl->col_pad = 1; tbl->row = ui_text_alloc(tbl->width); - INIT_LIST_HEAD(&tbl->cols); + CDS_INIT_LIST_HEAD(&tbl->cols); } void ui_table_uninit(struct ui_table *tbl) { struct ui_col *col, *tmp; - list_for_each_entry_safe(col, tmp, &tbl->cols, entry) + cds_list_for_each_entry_safe(col, tmp, &tbl->cols, entry) xfree(col); ui_text_free(tbl->row); @@ -87,7 +87,7 @@ static struct ui_col *ui_table_col_get(struct ui_table *tbl, uint32_t id) { struct ui_col *col; - list_for_each_entry(col, &tbl->cols, entry) { + cds_list_for_each_entry(col, &tbl->cols, entry) { if (col->id == id) return col; } @@ -100,7 +100,7 @@ static void __ui_table_pos_update(struct ui_table *tbl) struct ui_col *col; uint32_t pos = 0; - list_for_each_entry(col, &tbl->cols, entry) { + cds_list_for_each_entry(col, &tbl->cols, entry) { col->pos = pos; pos += col->len + tbl->col_pad; } @@ -115,7 +115,7 @@ void ui_table_col_add(struct ui_table *tbl, uint32_t id, char *name, uint32_t le col->len = len; col->align = UI_ALIGN_LEFT; - list_add_tail(&col->entry, &tbl->cols); + cds_list_add_tail(&col->entry, &tbl->cols); __ui_table_pos_update(tbl); } @@ -195,9 +195,8 @@ void ui_table_header_print(struct ui_table *tbl) mvprintw(tbl->y, tbl->x, "%*s", tbl->width, " "); attroff(tbl->hdr_color); - list_for_each_entry(col, &tbl->cols, entry) { + cds_list_for_each_entry(col, &tbl->cols, entry) { __ui_table_row_print(tbl, col, tbl->hdr_color, col->name); - } ui_table_row_show(tbl); @@ -1,10 +1,10 @@ #ifndef UI_H #define UI_H +#define _LGPL_SOURCE #include <stdbool.h> #include <inttypes.h> - -#include "list.h" +#include <urcu/list.h> enum ui_event_id { UI_EVT_SCROLL_LEFT, @@ -23,7 +23,7 @@ struct ui_text { }; struct ui_col { - struct list_head entry; + struct cds_list_head entry; uint32_t id; char *name; uint32_t len; @@ -36,7 +36,7 @@ struct ui_table { int y; int x; int rows_y; - struct list_head cols; + struct cds_list_head cols; struct ui_text *row; int hdr_color; int col_pad; |