Fix: add missing destroy functions to queues/stack APIs
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 22 Jun 2016 20:20:25 +0000 (16:20 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 22 Jun 2016 20:20:25 +0000 (16:20 -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 3dac178d62a68c261b298ce0a19e2856f8ab3dca..c974a4768171c7cfa7dfde15566804d18419fc7c 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);
+}
+
 void __cds_lfs_init(struct __cds_lfs_stack *s)
 {
        ___cds_lfs_init(s);
index 11a63d95cd3322a00c052a79080f1f93dd99e31c..5a9bca368775db300cbd1bac44e5fbcd51c6ce47 100644 (file)
@@ -95,6 +95,7 @@ typedef union {
 
 #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
@@ -119,12 +120,20 @@ typedef union {
 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_init: initialize lock-free stack.
+ * 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_init: initialize lock-free stack (without lock).
+ * Don't pair with any destroy function.
  */
 extern void __cds_lfs_init(struct __cds_lfs_stack *s);
 
index 7afe71e2f0eb82de8944e117666c3bfca484cb65..05d0bb478b8b169a03864272810d1b5c76bfa4f8 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)
@@ -79,7 +80,19 @@ void _cds_lfs_init(struct cds_lfs_stack *s)
 }
 
 /*
- * ___cds_lfs_init: initialize lock-free stack.
+ * 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);
+}
+
+/*
+ * ___cds_lfs_init: initialize lock-free stack (without lock).
+ * Don't pair with any destroy function.
  */
 static inline
 void ___cds_lfs_init(struct __cds_lfs_stack *s)
index 4ababbf0ee8e99974f585c1f3b236381a8f60b3c..67ac05ffd15e384dc42317e0d5b4d0c93d71c2d6 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)
@@ -107,7 +108,19 @@ static inline void _cds_wfcq_init(struct cds_wfcq_head *head,
 }
 
 /*
- * __cds_wfcq_init: initialize wait-free queue.
+ * 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_init: initialize wait-free queue (without lock). Don't
+ * pair with any destroy function.
  */
 static inline void ___cds_wfcq_init(struct __cds_wfcq_head *head,
                struct cds_wfcq_tail *tail)
index cc21fac53fa64f318a94420f92fe9883072e3ca1..df9f62f28bafa189a5b2f0d61fcbfce8b978b7b4 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 2666b0ef3ff806435ea81710e6add099b90e44af..e96c8876a2b916dcd5bde1e1ba2ad3f8b5ff4ec8 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. Don't pair with
+ * any destroy function.
  */
 static inline void ___cds_wfs_init(struct __cds_wfs_stack *s)
 {
@@ -85,7 +86,8 @@ static inline void ___cds_wfs_init(struct __cds_wfs_stack *s)
 }
 
 /*
- * 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)
@@ -97,6 +99,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 c65780e35887d93915849d7af4cff3e5bcc28b98..6c6ebba9e4453257da70484cecc6840bbdab0364 100644 (file)
@@ -135,6 +135,7 @@ struct cds_wfcq_tail {
 #define cds_wfcq_node_init             _cds_wfcq_node_init
 #define cds_wfcq_init                  _cds_wfcq_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
 
@@ -213,13 +214,22 @@ 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_init: initialize wait-free queue.
+ * 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_init: initialize wait-free queue (without lock). Don't
+ * pair with any destroy function.
  */
 extern void __cds_wfcq_init(struct __cds_wfcq_head *head,
                struct cds_wfcq_tail *tail);
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 28f61623638d0dc4ea03268f791e9d418668ef11..9d693053117ceb93e69034e433f2196a22c3070d 100644 (file)
@@ -108,6 +108,7 @@ typedef union {
 
 #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_init                 ___cds_wfs_init
 #define cds_wfs_empty                  _cds_wfs_empty
 #define cds_wfs_push                   _cds_wfs_push
@@ -146,12 +147,20 @@ typedef union {
 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_init: initialize wait-free stack.
+ * 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_init: initialize wait-free stack (no lock). Don't pair with
+ * any destroy function.
  */
 extern void __cds_wfs_init(struct __cds_wfs_stack *s);
 
index e28d51ad6dc0f17b853f1ac6ac1f76cbffc87ecf..85de8ecf9b29531b6cd1245dda4ca06cc8fde310 100644 (file)
@@ -40,6 +40,12 @@ void cds_wfcq_init(struct cds_wfcq_head *head,
        _cds_wfcq_init(head, tail);
 }
 
+void cds_wfcq_destroy(struct cds_wfcq_head *head,
+               struct cds_wfcq_tail *tail)
+{
+       _cds_wfcq_destroy(head, tail);
+}
+
 void __cds_wfcq_init(struct __cds_wfcq_head *head,
                struct cds_wfcq_tail *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 7618be3b38c51e1f824d13d0c0a6e10839874ec6..46300f92ce061176a4b2fe9339a85891c5d8f0e7 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);
+}
+
 void __cds_wfs_init(struct __cds_wfs_stack *s)
 {
        ___cds_wfs_init(s);
This page took 0.032485 seconds and 4 git commands to generate.