summaryrefslogtreecommitdiff
path: root/include/dom/core/node.h
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2021-07-03 13:54:26 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2021-07-03 13:54:26 +0100
commitc60dcdb27441b0e71072ad90ee14c67b73b84910 (patch)
tree5294d56a3294d893293ece0171ec69d36ae00279 /include/dom/core/node.h
parent6f9b1a501fa8b95ba0befc9f3eea815f2ba4035d (diff)
downloadlibdom-c60dcdb27441b0e71072ad90ee14c67b73b84910.tar.gz
libdom-c60dcdb27441b0e71072ad90ee14c67b73b84910.tar.bz2
WIP: Refcheck: Add dom node reference counting checking helper.tlsa/refcheck
Diffstat (limited to 'include/dom/core/node.h')
-rw-r--r--include/dom/core/node.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/include/dom/core/node.h b/include/dom/core/node.h
index 90026a1..37fd2b8 100644
--- a/include/dom/core/node.h
+++ b/include/dom/core/node.h
@@ -73,12 +73,18 @@ typedef enum {
typedef struct dom_node_internal dom_node_internal;
+struct dom_refcheck;
+struct dom_refcheck *dom_refcheck(
+ struct dom_refcheck *rc,
+ uint32_t refcnt);
+
/**
* DOM node type
*/
typedef struct dom_node {
const void *vtable;
uint32_t refcnt;
+ struct dom_refcheck *rc;
} dom_node;
/* DOM node vtable */
@@ -177,9 +183,11 @@ typedef struct dom_node_vtable {
static inline dom_node *dom_node_ref(dom_node *node)
{
- if (node != NULL)
+ if (node != NULL) {
node->refcnt++;
-
+ node->rc = dom_refcheck(node->rc, node->refcnt);
+ }
+
return node;
}
@@ -195,10 +203,11 @@ static inline dom_exception dom_node_try_destroy(dom_node *node)
static inline void dom_node_unref(dom_node *node)
{
if (node != NULL) {
- if (--node->refcnt == 0)
+ node->refcnt--;
+ node->rc = dom_refcheck(node->rc, node->refcnt);
+ if (node->refcnt == 0)
dom_node_try_destroy(node);
}
-
}
#define dom_node_unref(n) dom_node_unref((dom_node *) (n))