fix: handle EINTR correctly in get_cpu_mask_from_sysfs
[urcu.git] / include / urcu / static / wfqueue.h
index df9f62f28bafa189a5b2f0d61fcbfce8b978b7b4..0cb7b1b98cd965557121af56910687c94c2ecdd8 100644 (file)
@@ -1,34 +1,20 @@
+// SPDX-FileCopyrightText: 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
 #ifndef _URCU_WFQUEUE_STATIC_H
 #define _URCU_WFQUEUE_STATIC_H
 
 /*
- * wfqueue-static.h
- *
  * Userspace RCU library - Queue with Wait-Free Enqueue/Blocking Dequeue
  *
  * TO BE INCLUDED ONLY IN LGPL-COMPATIBLE CODE. See wfqueue.h for linking
  * dynamically with the userspace rcu library.
- *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <pthread.h>
-#include <assert.h>
 #include <poll.h>
+#include <urcu/assert.h>
 #include <urcu/compiler.h>
 #include <urcu/uatomic.h>
 
@@ -62,13 +48,13 @@ static inline void _cds_wfq_init(struct cds_wfq_queue *q)
        q->head = &q->dummy;
        q->tail = &q->dummy.next;
        ret = pthread_mutex_init(&q->lock, NULL);
-       assert(!ret);
+       urcu_posix_assert(!ret);
 }
 
 static inline void _cds_wfq_destroy(struct cds_wfq_queue *q)
 {
        int ret = pthread_mutex_destroy(&q->lock);
-       assert(!ret);
+       urcu_posix_assert(!ret);
 }
 
 static inline void _cds_wfq_enqueue(struct cds_wfq_queue *q,
@@ -81,13 +67,14 @@ static inline void _cds_wfq_enqueue(struct cds_wfq_queue *q,
         * structure containing node and setting node->next to NULL before
         * publication.
         */
-       old_tail = uatomic_xchg(&q->tail, &node->next);
+       cmm_emit_legacy_smp_mb();
+       old_tail = uatomic_xchg_mo(&q->tail, &node->next, CMM_SEQ_CST);
        /*
         * At this point, dequeuers see a NULL old_tail->next, which indicates
         * that the queue is being appended to. The following store will append
         * "node" to the queue from a dequeuer perspective.
         */
-       CMM_STORE_SHARED(*old_tail, node);
+       uatomic_store(old_tail, node, CMM_RELEASE);
 }
 
 /*
@@ -102,7 +89,7 @@ ___cds_wfq_node_sync_next(struct cds_wfq_node *node)
        /*
         * Adaptative busy-looping waiting for enqueuer to complete enqueue.
         */
-       while ((next = CMM_LOAD_SHARED(node->next)) == NULL) {
+       while ((next = uatomic_load(&node->next, CMM_CONSUME)) == NULL) {
                if (++attempt >= WFQ_ADAPT_ATTEMPTS) {
                        (void) poll(NULL, 0, WFQ_WAIT); /* Wait for 10ms */
                        attempt = 0;
@@ -129,7 +116,7 @@ ___cds_wfq_dequeue_blocking(struct cds_wfq_queue *q)
        /*
         * Queue is empty if it only contains the dummy node.
         */
-       if (q->head == &q->dummy && CMM_LOAD_SHARED(q->tail) == &q->dummy.next)
+       if (q->head == &q->dummy && uatomic_load(&q->tail, CMM_CONSUME) == &q->dummy.next)
                return NULL;
        node = q->head;
 
@@ -157,10 +144,10 @@ _cds_wfq_dequeue_blocking(struct cds_wfq_queue *q)
        int ret;
 
        ret = pthread_mutex_lock(&q->lock);
-       assert(!ret);
+       urcu_posix_assert(!ret);
        retnode = ___cds_wfq_dequeue_blocking(q);
        ret = pthread_mutex_unlock(&q->lock);
-       assert(!ret);
+       urcu_posix_assert(!ret);
        return retnode;
 }
 
This page took 0.025956 seconds and 4 git commands to generate.