Fix: add missing destroy functions to queues/stack APIs
[urcu.git] / urcu / wfcqueue.h
index df26e339692b4694590352fa4454b366a67137e0..6c6ebba9e4453257da70484cecc6840bbdab0364 100644 (file)
@@ -43,7 +43,7 @@ extern "C" {
  * McKenney.
  */
 
-#define CDS_WFCQ_WOULDBLOCK    ((void *) -1UL)
+#define CDS_WFCQ_WOULDBLOCK    ((struct cds_wfcq_node *) -1UL)
 
 enum cds_wfcq_ret {
        CDS_WFCQ_RET_WOULDBLOCK =       -1,
@@ -74,16 +74,56 @@ struct cds_wfcq_head {
        pthread_mutex_t lock;
 };
 
+#ifndef __cplusplus
 /*
  * The transparent union allows calling functions that work on both
  * struct cds_wfcq_head and struct __cds_wfcq_head on any of those two
  * types.
  */
-typedef union __attribute__((__transparent_union__)) {
+typedef union {
+       struct __cds_wfcq_head *_h;
+       struct cds_wfcq_head *h;
+} __attribute__((__transparent_union__)) cds_wfcq_head_ptr_t;
+
+/*
+ * This static inline is only present for compatibility with C++. It is
+ * effect-less in C.
+ */
+static inline struct __cds_wfcq_head *__cds_wfcq_head_cast(struct __cds_wfcq_head *head)
+{
+       return head;
+}
+
+/*
+ * This static inline is only present for compatibility with C++. It is
+ * effect-less in C.
+ */
+static inline struct cds_wfcq_head *cds_wfcq_head_cast(struct cds_wfcq_head *head)
+{
+       return head;
+}
+#else /* #ifndef __cplusplus */
+
+/* C++ ignores transparent union. */
+typedef union {
        struct __cds_wfcq_head *_h;
        struct cds_wfcq_head *h;
 } cds_wfcq_head_ptr_t;
 
+/* C++ ignores transparent union. Requires an explicit conversion. */
+static inline cds_wfcq_head_ptr_t __cds_wfcq_head_cast(struct __cds_wfcq_head *head)
+{
+       cds_wfcq_head_ptr_t ret = { ._h = head };
+       return ret;
+}
+/* C++ ignores transparent union. Requires an explicit conversion. */
+static inline cds_wfcq_head_ptr_t cds_wfcq_head_cast(struct cds_wfcq_head *head)
+{
+       cds_wfcq_head_ptr_t ret = { .h = head };
+       return ret;
+}
+#endif /* #else #ifndef __cplusplus */
+
 struct cds_wfcq_tail {
        struct cds_wfcq_node *p;
 };
@@ -94,6 +134,8 @@ 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
 
@@ -172,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);
This page took 0.024374 seconds and 4 git commands to generate.