| 1 | #ifndef _LTTNG_WRAPPER_RCU_H |
| 2 | #define _LTTNG_WRAPPER_RCU_H |
| 3 | |
| 4 | /* |
| 5 | * wrapper/rcu.h |
| 6 | * |
| 7 | * wrapper around linux/rcupdate.h and linux/rculist.h. |
| 8 | * |
| 9 | * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public |
| 13 | * License as published by the Free Software Foundation; only |
| 14 | * version 2.1 of the License. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Lesser General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Lesser General Public |
| 22 | * License along with this library; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | |
| 26 | #include <linux/version.h> |
| 27 | #include <linux/rculist.h> |
| 28 | #include <linux/rcupdate.h> |
| 29 | #include "list.h" |
| 30 | |
| 31 | #ifndef rcu_dereference_raw_notrace |
| 32 | #define rcu_dereference_raw_notrace(p) rcu_dereference_raw(p) |
| 33 | #endif |
| 34 | |
| 35 | #define lttng_rcu_dereference(p) rcu_dereference_raw_notrace(p) |
| 36 | |
| 37 | /** |
| 38 | * lttng_list_entry_rcu - get the struct for this entry |
| 39 | * @ptr: the &struct list_head pointer. |
| 40 | * @type: the type of the struct this is embedded in. |
| 41 | * @member: the name of the list_head within the struct. |
| 42 | * |
| 43 | * This primitive may safely run concurrently with the _rcu list-mutation |
| 44 | * primitives such as list_add_rcu() as long as it's guarded by |
| 45 | * rcu_read_lock_sched(). |
| 46 | * Can be used while tracing RCU. |
| 47 | */ |
| 48 | #define lttng_list_entry_rcu(ptr, type, member) \ |
| 49 | ({ \ |
| 50 | typeof(*ptr) __rcu *__ptr = (typeof(*ptr) __rcu __force *)ptr; \ |
| 51 | container_of((typeof(ptr))lttng_rcu_dereference(__ptr), type, member); \ |
| 52 | }) |
| 53 | |
| 54 | /** |
| 55 | * lttng_list_for_each_entry_rcu - iterate over rcu list of given type |
| 56 | * @pos: the type * to use as a loop cursor. |
| 57 | * @head: the head for your list. |
| 58 | * @member: the name of the list_head within the struct. |
| 59 | * |
| 60 | * This list-traversal primitive may safely run concurrently with |
| 61 | * the _rcu list-mutation primitives such as list_add_rcu() |
| 62 | * as long as the traversal is guarded by rcu_read_lock_sched(). |
| 63 | * Can be used while tracing RCU. |
| 64 | */ |
| 65 | #define lttng_list_for_each_entry_rcu(pos, head, member) \ |
| 66 | for (pos = lttng_list_entry_rcu((head)->next, typeof(*pos), member); \ |
| 67 | &pos->member != (head); \ |
| 68 | pos = lttng_list_entry_rcu(pos->member.next, typeof(*pos), member)) |
| 69 | |
| 70 | /** |
| 71 | * lttng_hlist_for_each_entry_rcu - iterate over rcu list of given type (for tracing) |
| 72 | * @pos: the type * to use as a loop cursor. |
| 73 | * @head: the head for your list. |
| 74 | * @member: the name of the hlist_node within the struct. |
| 75 | * |
| 76 | * This list-traversal primitive may safely run concurrently with |
| 77 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
| 78 | * as long as the traversal is guarded by rcu_read_lock(). |
| 79 | * |
| 80 | * This is the same as hlist_for_each_entry_rcu() except that it does |
| 81 | * not do any RCU debugging or tracing. |
| 82 | */ |
| 83 | #define lttng_hlist_for_each_entry_rcu(pos, head, member) \ |
| 84 | for (pos = lttng_hlist_entry_safe (lttng_rcu_dereference(hlist_first_rcu(head)), \ |
| 85 | typeof(*(pos)), member); \ |
| 86 | pos; \ |
| 87 | pos = lttng_hlist_entry_safe(lttng_rcu_dereference(hlist_next_rcu( \ |
| 88 | &(pos)->member)), typeof(*(pos)), member)) |
| 89 | |
| 90 | #endif /* _LTTNG_WRAPPER_RCU_H */ |