Fix: add missing destroy functions to queues/stack APIs
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 22 Jun 2016 20:37:47 +0000 (16:37 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 22 Jun 2016 20:37:47 +0000 (16:37 -0400)
Queues and stack APIs that invoke pthread_mutex_init() should have a
"destroy" counterpart which calls pthread_mutex_destroy(), ortherwise
this causes small memory leaks on platforms where pthread_mutex_init
performs memory allocation.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 files changed:
lfstack.c
urcu/lfstack.h
urcu/static/lfstack.h
urcu/static/wfcqueue.h
urcu/static/wfqueue.h
urcu/static/wfstack.h
urcu/wfcqueue.h
urcu/wfqueue.h
urcu/wfstack.h
wfcqueue.c
wfqueue.c
wfstack.c

index db2c2cf97cf1dfd3559deb2a77e13c12de542ffe..30f1daaeeeeca66b93eb1c49b9c26a74f70d5da1 100644 (file)
--- a/lfstack.c
+++ b/lfstack.c
@@ -40,6 +40,11 @@ void cds_lfs_init(struct cds_lfs_stack *s)
        _cds_lfs_init(s);
 }
 
+void cds_lfs_destroy(struct cds_lfs_stack *s)
+{
+       _cds_lfs_destroy(s);
+}
+
 bool cds_lfs_empty(struct cds_lfs_stack *s)
 {
        return _cds_lfs_empty(s);
index bd17ee6400065c37f56eeeedcf0cc147a4a60f3c..d5bc77503d10d633f6b805e0191fa9bbac3f6535 100644 (file)
@@ -81,6 +81,7 @@ struct cds_lfs_stack {
 
 #define cds_lfs_node_init              _cds_lfs_node_init
 #define cds_lfs_init                   _cds_lfs_init
+#define cds_lfs_destroy                        _cds_lfs_destroy
 #define __cds_lfs_init                 ___cds_lfs_init
 #define cds_lfs_empty                  _cds_lfs_empty
 #define cds_lfs_push                   _cds_lfs_push
@@ -105,10 +106,17 @@ struct cds_lfs_stack {
 extern void cds_lfs_node_init(struct cds_lfs_node *node);
 
 /*
- * cds_lfs_init: initialize lock-free stack.
+ * cds_lfs_init: initialize lock-free stack (with locking). Pair with
+ * cds_lfs_destroy().
  */
 extern void cds_lfs_init(struct cds_lfs_stack *s);
 
+/*
+ * cds_lfs_destroy: destroy lock-free stack (with lock). Pair with
+ * cds_lfs_init().
+ */
+extern void cds_lfs_destroy(struct cds_lfs_stack *s);
+
 /*
  * cds_lfs_empty: return whether lock-free stack is empty.
  *
index b49eb205a45ab3e5f409fc2ee9c490aa04e73e0e..967071a0cffcf74ba86465362efb7ae1fb17514f 100644 (file)
@@ -66,7 +66,8 @@ void _cds_lfs_node_init(struct cds_lfs_node *node)
 }
 
 /*
- * cds_lfs_init: initialize lock-free stack.
+ * cds_lfs_init: initialize lock-free stack (with lock). Pair with
+ * cds_lfs_destroy().
  */
 static inline
 void _cds_lfs_init(struct cds_lfs_stack *s)
@@ -78,6 +79,17 @@ void _cds_lfs_init(struct cds_lfs_stack *s)
        assert(!ret);
 }
 
+/*
+ * cds_lfs_destroy: destroy lock-free stack (with lock). Pair with
+ * cds_lfs_init().
+ */
+static inline
+void _cds_lfs_destroy(struct cds_lfs_stack *s)
+{
+        int ret = pthread_mutex_destroy(&s->lock);
+       assert(!ret);
+}
+
 static inline
 bool ___cds_lfs_empty_head(struct cds_lfs_head *head)
 {
index 62e003f98a4029a08f20e85b3a2c67f1b593ac03..0d2facbc212a89dceae359b181a3b421cc4c0292 100644 (file)
@@ -92,7 +92,8 @@ static inline void _cds_wfcq_node_init(struct cds_wfcq_node *node)
 }
 
 /*
- * cds_wfcq_init: initialize wait-free queue.
+ * cds_wfcq_init: initialize wait-free queue (with lock). Pair with
+ * cds_wfcq_destroy().
  */
 static inline void _cds_wfcq_init(struct cds_wfcq_head *head,
                struct cds_wfcq_tail *tail)
@@ -106,6 +107,17 @@ static inline void _cds_wfcq_init(struct cds_wfcq_head *head,
        assert(!ret);
 }
 
+/*
+ * cds_wfcq_destroy: destroy wait-free queue (with lock). Pair with
+ * cds_wfcq_init().
+ */
+static inline void _cds_wfcq_destroy(struct cds_wfcq_head *head,
+               struct cds_wfcq_tail *tail)
+{
+       int ret = pthread_mutex_destroy(&head->lock);
+       assert(!ret);
+}
+
 /*
  * cds_wfcq_empty: return whether wait-free queue is empty.
  *
index 636e1afa8e949e19bae448b1d5775eefd202f717..1a7a99f4e5c13fcbebd31931481c98fb504ef193 100644 (file)
@@ -65,6 +65,12 @@ static inline void _cds_wfq_init(struct cds_wfq_queue *q)
        assert(!ret);
 }
 
+static inline void _cds_wfq_destroy(struct cds_wfq_queue *q)
+{
+       int ret = pthread_mutex_destroy(&q->lock);
+       assert(!ret);
+}
+
 static inline void _cds_wfq_enqueue(struct cds_wfq_queue *q,
                                    struct cds_wfq_node *node)
 {
index db0d5b8b1abda178f7cf0e14a0530d5bae43f8aa..9efba0ee6185051c41d2816b0653d2b4191c78e3 100644 (file)
@@ -77,7 +77,8 @@ void _cds_wfs_node_init(struct cds_wfs_node *node)
 }
 
 /*
- * cds_wfs_init: initialize wait-free stack.
+ * cds_wfs_init: initialize wait-free stack. Pair with
+ * cds_wfs_destroy().
  */
 static inline
 void _cds_wfs_init(struct cds_wfs_stack *s)
@@ -89,6 +90,17 @@ void _cds_wfs_init(struct cds_wfs_stack *s)
        assert(!ret);
 }
 
+/*
+ * cds_wfs_destroy: destroy wait-free stack. Pair with
+ * cds_wfs_init().
+ */
+static inline
+void _cds_wfs_destroy(struct cds_wfs_stack *s)
+{
+       int ret = pthread_mutex_destroy(&s->lock);
+       assert(!ret);
+}
+
 static inline bool ___cds_wfs_end(void *node)
 {
        return node == CDS_WFS_END;
index 652b42d3ab5da2adda7027f490af4230460a2448..7e363ea8b526c2fcab8f03cee670bb8ac3052dcf 100644 (file)
@@ -80,6 +80,7 @@ struct cds_wfcq_tail {
 
 #define cds_wfcq_node_init             _cds_wfcq_node_init
 #define cds_wfcq_init                  _cds_wfcq_init
+#define cds_wfcq_destroy               _cds_wfcq_destroy
 #define cds_wfcq_empty                 _cds_wfcq_empty
 #define cds_wfcq_enqueue               _cds_wfcq_enqueue
 
@@ -158,11 +159,19 @@ struct cds_wfcq_tail {
 extern void cds_wfcq_node_init(struct cds_wfcq_node *node);
 
 /*
- * cds_wfcq_init: initialize wait-free queue.
+ * cds_wfcq_init: initialize wait-free queue. Pair with
+ * cds_wfcq_destroy().
  */
 extern void cds_wfcq_init(struct cds_wfcq_head *head,
                struct cds_wfcq_tail *tail);
 
+/*
+ * cds_wfcq_destroy: destroy wait-free queue. Pair with
+ * cds_wfcq_init().
+ */
+extern void cds_wfcq_destroy(struct cds_wfcq_head *head,
+               struct cds_wfcq_tail *tail);
+
 /*
  * cds_wfcq_empty: return whether wait-free queue is empty.
  *
index 4cd4b135860c2c59ac5c88bfe9298eaff3a1adfe..2ba86248aa7095c4ca83e94b13769c073507a58c 100644 (file)
@@ -71,6 +71,12 @@ void cds_wfq_init(struct cds_wfq_queue *q)
        _cds_wfq_init(q);
 }
 
+static inline CDS_WFQ_DEPRECATED
+void cds_wfq_destroy(struct cds_wfq_queue *q)
+{
+       _cds_wfq_destroy(q);
+}
+
 static inline CDS_WFQ_DEPRECATED
 void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node)
 {
@@ -97,6 +103,9 @@ void cds_wfq_node_init(struct cds_wfq_node *node);
 extern CDS_WFQ_DEPRECATED
 void cds_wfq_init(struct cds_wfq_queue *q);
 
+extern CDS_WFQ_DEPRECATED
+void cds_wfq_destroy(struct cds_wfq_queue *q);
+
 extern CDS_WFQ_DEPRECATED
 void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node);
 
index fc0b44b791fcf218c56714711e235cc40465296f..5ef8bab04825091232e939aff9d75e19b929f11c 100644 (file)
@@ -94,6 +94,7 @@ struct cds_wfs_stack {
 
 #define cds_wfs_node_init              _cds_wfs_node_init
 #define cds_wfs_init                   _cds_wfs_init
+#define cds_wfs_destroy                        _cds_wfs_destroy
 #define cds_wfs_empty                  _cds_wfs_empty
 #define cds_wfs_push                   _cds_wfs_push
 
@@ -131,10 +132,17 @@ struct cds_wfs_stack {
 extern void cds_wfs_node_init(struct cds_wfs_node *node);
 
 /*
- * cds_wfs_init: initialize wait-free stack.
+ * cds_wfs_init: initialize wait-free stack (with lock). Pair with
+ * cds_wfs_destroy().
  */
 extern void cds_wfs_init(struct cds_wfs_stack *s);
 
+/*
+ * cds_wfs_destroy: destroy wait-free stack (with lock). Pair with
+ * cds_wfs_init().
+ */
+extern void cds_wfs_destroy(struct cds_wfs_stack *s);
+
 /*
  * cds_wfs_empty: return whether wait-free stack is empty.
  *
index 4950c1008ebbd69c51bff06ae6cf929ef4bc5b73..7f8b588e997b31c0d199ace6c14a4507d9b6b02a 100644 (file)
@@ -40,9 +40,14 @@ void cds_wfcq_init(struct cds_wfcq_head *head,
        _cds_wfcq_init(head, tail);
 }
 
-bool cds_wfcq_empty(struct cds_wfcq_head *head,
+void cds_wfcq_destroy(struct cds_wfcq_head *head,
                struct cds_wfcq_tail *tail)
+{
+       _cds_wfcq_destroy(head, tail);
+}
 
+bool cds_wfcq_empty(struct cds_wfcq_head *head,
+               struct cds_wfcq_tail *tail)
 {
        return _cds_wfcq_empty(head, tail);
 }
index 14272cb2eefba483bcb7a949209965684838597a..509f4f9c6275b1511916f7046c40ffbd978c99d7 100644 (file)
--- a/wfqueue.c
+++ b/wfqueue.c
@@ -41,6 +41,11 @@ void cds_wfq_init(struct cds_wfq_queue *q)
        _cds_wfq_init(q);
 }
 
+void cds_wfq_destroy(struct cds_wfq_queue *q)
+{
+       _cds_wfq_destroy(q);
+}
+
 void cds_wfq_enqueue(struct cds_wfq_queue *q, struct cds_wfq_node *node)
 {
        _cds_wfq_enqueue(q, node);
index c8bd7e6214211190be827474c301718882daf7c9..48382806d5ee533b00a2b364df644782a14a90b8 100644 (file)
--- a/wfstack.c
+++ b/wfstack.c
@@ -38,6 +38,11 @@ void cds_wfs_init(struct cds_wfs_stack *s)
        _cds_wfs_init(s);
 }
 
+void cds_wfs_destroy(struct cds_wfs_stack *s)
+{
+       _cds_wfs_destroy(s);
+}
+
 bool cds_wfs_empty(struct cds_wfs_stack *s)
 {
        return _cds_wfs_empty(s);
This page took 0.031782 seconds and 4 git commands to generate.