1 /* Copyright © 2014 Brandon L Black <blblack@gmail.com> 2 * 3 * This file is part of gdnsd. 4 * 5 * gdnsd is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * gdnsd is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with gdnsd. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 #ifndef GDNSD_PRCU_H 21 #define GDNSD_PRCU_H 22 23 #include <pthread.h> 24 25 // source for GDNSD_B_QSBR definition for out-of-tree includers 26 #ifndef GDNSD_SOURCE_TREE 27 #include <gdnsd/bopts.h> 28 #endif 29 30 #pragma GCC visibility push(default) 31 extern pthread_rwlock_t gdnsd_prcu_rwlock_; 32 #pragma GCC visibility pop 33 34 // comes from config.h in-tree, or above if out-of-tree 35 #if GDNSD_B_QSBR 36 37 // in-tree we define _LGPL_SOURCE anyways which is a superset of 38 // URCU_INLINE_SMALL_FUNCTIONS, but this will help for consumers 39 // of this header which aren't LGPL-compat 40 #define URCU_INLINE_SMALL_FUNCTIONS 1 41 #include <urcu-qsbr.h> 42 43 #define gdnsd_prcu_rdr_thread_start() rcu_register_thread() 44 #define gdnsd_prcu_rdr_online() rcu_thread_online() 45 #define gdnsd_prcu_rdr_quiesce() rcu_quiescent_state() 46 #define gdnsd_prcu_rdr_lock() rcu_read_lock() 47 #define gdnsd_prcu_rdr_deref(s) rcu_dereference((s)) 48 #define gdnsd_prcu_rdr_unlock() rcu_read_unlock() 49 #define gdnsd_prcu_rdr_offline() rcu_thread_offline() 50 #define gdnsd_prcu_rdr_thread_end() rcu_unregister_thread() 51 52 #define gdnsd_prcu_upd_lock() do { } while(0) 53 #define gdnsd_prcu_upd_assign(d,s) rcu_assign_pointer((d),(s)) 54 #define gdnsd_prcu_upd_unlock() synchronize_rcu() 55 56 #else // !GDNSD_B_QSBR 57 58 #define gdnsd_prcu_rdr_thread_start() do { } while(0) 59 #define gdnsd_prcu_rdr_online() do { } while(0) 60 #define gdnsd_prcu_rdr_quiesce() do { } while(0) 61 #define gdnsd_prcu_rdr_lock() pthread_rwlock_rdlock(&gdnsd_prcu_rwlock_) 62 #define gdnsd_prcu_rdr_deref(s) (s) 63 #define gdnsd_prcu_rdr_unlock() pthread_rwlock_unlock(&gdnsd_prcu_rwlock_) 64 #define gdnsd_prcu_rdr_offline() do { } while(0) 65 #define gdnsd_prcu_rdr_thread_end() do { } while(0) 66 67 #define gdnsd_prcu_upd_lock() pthread_rwlock_wrlock(&gdnsd_prcu_rwlock_) 68 #define gdnsd_prcu_upd_assign(d,s) (d) = (s) 69 #define gdnsd_prcu_upd_unlock() pthread_rwlock_unlock(&gdnsd_prcu_rwlock_) 70 71 #endif // GDNSD_B_QSBR 72 73 #endif // GDNSD_PRCU_H 74