[DTrace-devel] [PATCH 06/16] Introduce a standard implementation for *_add and _del htab functions
Kris Van Hees
kris.van.hees at oracle.com
Thu Mar 18 21:54:28 PDT 2021
The add and del functions are expected to follow a specific template
and can therefore be implemented by means of a generic macro. The
probe-specific version is modified to make use of this new generic
macro. The new macro is DEFINE_HE_STD_LINK_FUNCS.
We also introduce a DEFINE_HTAB_STD_OPS macro to can be used to
define a htab operations struct.
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
libdtrace/dt_htab.h | 51 ++++++++++++++++++++++++++++++++++++++
libdtrace/dt_probe.c | 59 +++++---------------------------------------
2 files changed, 57 insertions(+), 53 deletions(-)
diff --git a/libdtrace/dt_htab.h b/libdtrace/dt_htab.h
index 00a480a8..48868ccb 100644
--- a/libdtrace/dt_htab.h
+++ b/libdtrace/dt_htab.h
@@ -19,6 +19,57 @@ typedef int (*htab_cmp_fn)(const void *, const void *);
typedef void *(*htab_add_fn)(void *, void *);
typedef void *(*htab_del_fn)(void *, void *);
+#define DEFINE_HE_STD_LINK_FUNCS(ID, TYPE, HE) \
+ static TYPE *ID##_add(TYPE *head, TYPE *new) \
+ { \
+ if (!head) \
+ return new; \
+ \
+ new->HE.next = head; \
+ head->HE.prev = new; \
+ \
+ return new; \
+ } \
+ \
+ static TYPE *ID##_del(TYPE *head, TYPE *ent) \
+ { \
+ TYPE *prev = ent->HE.prev; \
+ TYPE *next = ent->HE.next; \
+ \
+ if (head == ent) { \
+ if (!next) \
+ return NULL; \
+ \
+ head = next; \
+ head->HE.prev = NULL; \
+ ent->HE.next = NULL; \
+ \
+ return head; \
+ } \
+ \
+ if (!next) { \
+ prev->HE.next = NULL; \
+ ent->HE.prev = NULL; \
+ \
+ return head; \
+ } \
+ \
+ prev->HE.next = next; \
+ next->HE.prev = prev; \
+ ent->HE.prev = ent->HE.next = NULL; \
+ \
+ return head; \
+ }
+
+#define DEFINE_HTAB_STD_OPS(ID) \
+ static dt_htab_ops_t ID##_htab_ops = { \
+ .hval = (htab_hval_fn)ID##_hval, \
+ .cmp = (htab_cmp_fn)ID##_cmp, \
+ .add = (htab_add_fn)ID##_add, \
+ .del = (htab_del_fn)ID##_del, \
+ };
+
+
typedef struct dt_htab_ops {
htab_hval_fn hval;
htab_cmp_fn cmp;
diff --git a/libdtrace/dt_probe.c b/libdtrace/dt_probe.c
index f08ebef3..b84182ef 100644
--- a/libdtrace/dt_probe.c
+++ b/libdtrace/dt_probe.c
@@ -44,54 +44,7 @@ typedef struct dt_probeclause {
DEFINE_HE_LINK_FUNCS(id)
#define DEFINE_HE_LINK_FUNCS(id) \
- static dt_probe_t *id##_add(dt_probe_t *head, dt_probe_t *new) \
- { \
- if (!head) \
- return new; \
- \
- new->he_##id.next = head; \
- head->he_##id.prev = new; \
- \
- return new; \
- } \
- \
- static dt_probe_t *id##_del(dt_probe_t *head, dt_probe_t *probe) \
- { \
- dt_probe_t *prev = probe->he_##id.prev; \
- dt_probe_t *next = probe->he_##id.next; \
- \
- if (head == probe) { \
- if (!next) \
- return NULL; \
- \
- head = next; \
- head->he_##id.prev = NULL; \
- probe->he_##id.next = NULL; \
- \
- return head; \
- } \
- \
- if (!next) { \
- prev->he_##id.next = NULL; \
- probe->he_##id.prev = NULL; \
- \
- return head; \
- } \
- \
- prev->he_##id.next = next; \
- next->he_##id.prev = prev; \
- probe->he_##id.prev = probe->he_##id.next = NULL; \
- \
- return head; \
- }
-
-#define DEFINE_HTAB_OPS(id) \
- static dt_htab_ops_t id##_htab_ops = { \
- .hval = (htab_hval_fn)id##_hval, \
- .cmp = (htab_cmp_fn)id##_cmp, \
- .add = (htab_add_fn)id##_add, \
- .del = (htab_del_fn)id##_del, \
- };
+ DEFINE_HE_STD_LINK_FUNCS(id, dt_probe_t, he_##id)
DEFINE_HE_FUNCS(prv)
DEFINE_HE_FUNCS(mod)
@@ -140,11 +93,11 @@ static int fqn_cmp(const dt_probe_t *p, const dt_probe_t *q)
DEFINE_HE_LINK_FUNCS(fqn)
-DEFINE_HTAB_OPS(prv)
-DEFINE_HTAB_OPS(mod)
-DEFINE_HTAB_OPS(fun)
-DEFINE_HTAB_OPS(prb)
-DEFINE_HTAB_OPS(fqn)
+DEFINE_HTAB_STD_OPS(prv)
+DEFINE_HTAB_STD_OPS(mod)
+DEFINE_HTAB_STD_OPS(fun)
+DEFINE_HTAB_STD_OPS(prb)
+DEFINE_HTAB_STD_OPS(fqn)
static uint8_t
dt_probe_argmap(dt_node_t *xnp, dt_node_t *nnp)
--
2.28.0
More information about the DTrace-devel
mailing list