X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Furcu-qsbr.c;h=e7ee180a9f81119a091de2d3156203028debb2bb;hb=601922a81d884e16ff404cee7534ede56fb87d0a;hp=318ab29c6e34afbd6957b90916c3cf84e03fe1bf;hpb=90f72b8c054ca4e3b4b45f630549c784e26ce79a;p=urcu.git diff --git a/src/urcu-qsbr.c b/src/urcu-qsbr.c index 318ab29..e7ee180 100644 --- a/src/urcu-qsbr.c +++ b/src/urcu-qsbr.c @@ -1,25 +1,11 @@ +// SPDX-FileCopyrightText: 2009 Mathieu Desnoyers +// SPDX-FileCopyrightText: 2009 Paul E. McKenney, IBM Corporation. +// +// SPDX-License-Identifier: LGPL-2.1-or-later + /* - * urcu-qsbr.c - * * Userspace RCU QSBR library * - * Copyright (c) 2009 Mathieu Desnoyers - * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. - * - * 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 - * * IBM's contributions to this file may be relicensed under LGPLv2 or later. */ @@ -34,6 +20,7 @@ #include #include +#include #include #include #include @@ -156,7 +143,8 @@ static void wait_gp(void) */ static void wait_for_readers(struct cds_list_head *input_readers, struct cds_list_head *cur_snap_readers, - struct cds_list_head *qsreaders) + struct cds_list_head *qsreaders, + cmm_annotate_t *group) { unsigned int wait_loops = 0; struct urcu_qsbr_reader *index, *tmp; @@ -183,7 +171,7 @@ static void wait_for_readers(struct cds_list_head *input_readers, cmm_smp_mb(); } cds_list_for_each_entry_safe(index, tmp, input_readers, node) { - switch (urcu_qsbr_reader_state(&index->ctr)) { + switch (urcu_qsbr_reader_state(&index->ctr, group)) { case URCU_READER_ACTIVE_CURRENT: if (cur_snap_readers) { cds_list_move(&index->node, @@ -208,8 +196,7 @@ static void wait_for_readers(struct cds_list_head *input_readers, if (cds_list_empty(input_readers)) { if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) { /* Read reader_gp before write futex */ - cmm_smp_mb(); - uatomic_set(&urcu_qsbr_gp.futex, 0); + uatomic_store(&urcu_qsbr_gp.futex, 0, CMM_RELEASE); } break; } else { @@ -238,6 +225,8 @@ static void wait_for_readers(struct cds_list_head *input_readers, #if (CAA_BITS_PER_LONG < 64) void urcu_qsbr_synchronize_rcu(void) { + cmm_annotate_define(acquire_group); + cmm_annotate_define(release_group); CDS_LIST_HEAD(cur_snap_readers); CDS_LIST_HEAD(qsreaders); unsigned long was_online; @@ -258,6 +247,7 @@ void urcu_qsbr_synchronize_rcu(void) urcu_qsbr_thread_offline(); else cmm_smp_mb(); + cmm_annotate_group_mb_release(&release_group); /* * Add ourself to gp_waiters queue of threads awaiting to wait @@ -289,7 +279,7 @@ void urcu_qsbr_synchronize_rcu(void) * wait_for_readers() can release and grab again rcu_registry_lock * internally. */ - wait_for_readers(®istry, &cur_snap_readers, &qsreaders); + wait_for_readers(®istry, &cur_snap_readers, &qsreaders, &acquire_group); /* * Must finish waiting for quiescent state for original parity @@ -309,7 +299,8 @@ void urcu_qsbr_synchronize_rcu(void) cmm_smp_mb(); /* Switch parity: 0 -> 1, 1 -> 0 */ - CMM_STORE_SHARED(urcu_qsbr_gp.ctr, urcu_qsbr_gp.ctr ^ URCU_QSBR_GP_CTR); + cmm_annotate_group_mem_release(&release_group, &urcu_qsbr_gp.ctr); + uatomic_store(&urcu_qsbr_gp.ctr, urcu_qsbr_gp.ctr ^ URCU_QSBR_GP_CTR, CMM_RELAXED); /* * Must commit urcu_qsbr_gp.ctr update to memory before waiting for @@ -332,7 +323,7 @@ void urcu_qsbr_synchronize_rcu(void) * wait_for_readers() can release and grab again rcu_registry_lock * internally. */ - wait_for_readers(&cur_snap_readers, NULL, &qsreaders); + wait_for_readers(&cur_snap_readers, NULL, &qsreaders, &acquire_group); /* * Put quiescent reader list back into registry. @@ -347,6 +338,8 @@ gp_end: * Finish waiting for reader threads before letting the old ptr being * freed. */ + cmm_annotate_group_mb_acquire(&acquire_group); + if (was_online) urcu_qsbr_thread_online(); else @@ -355,6 +348,8 @@ gp_end: #else /* !(CAA_BITS_PER_LONG < 64) */ void urcu_qsbr_synchronize_rcu(void) { + cmm_annotate_define(acquire_group); + cmm_annotate_define(release_group); CDS_LIST_HEAD(qsreaders); unsigned long was_online; DEFINE_URCU_WAIT_NODE(wait, URCU_WAIT_WAITING); @@ -371,6 +366,7 @@ void urcu_qsbr_synchronize_rcu(void) urcu_qsbr_thread_offline(); else cmm_smp_mb(); + cmm_annotate_group_mb_release(&release_group); /* * Add ourself to gp_waiters queue of threads awaiting to wait @@ -398,7 +394,8 @@ void urcu_qsbr_synchronize_rcu(void) goto out; /* Increment current G.P. */ - CMM_STORE_SHARED(urcu_qsbr_gp.ctr, urcu_qsbr_gp.ctr + URCU_QSBR_GP_CTR); + cmm_annotate_group_mem_release(&release_group, &urcu_qsbr_gp.ctr); + uatomic_store(&urcu_qsbr_gp.ctr, urcu_qsbr_gp.ctr + URCU_QSBR_GP_CTR, CMM_RELAXED); /* * Must commit urcu_qsbr_gp.ctr update to memory before waiting for @@ -421,7 +418,7 @@ void urcu_qsbr_synchronize_rcu(void) * wait_for_readers() can release and grab again rcu_registry_lock * internally. */ - wait_for_readers(®istry, NULL, &qsreaders); + wait_for_readers(®istry, NULL, &qsreaders, &acquire_group); /* * Put quiescent reader list back into registry. @@ -436,6 +433,8 @@ gp_end: urcu_qsbr_thread_online(); else cmm_smp_mb(); + + cmm_annotate_group_mb_acquire(&acquire_group); } #endif /* !(CAA_BITS_PER_LONG < 64) */