Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 1 | /* IRQ-safe linked lists |
| 2 | * |
| 3 | * (C) 2015-2017 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * This program 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 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program 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 this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
| 18 | */ |
Harald Welte | 9f240b6 | 2016-03-18 10:32:56 +0100 | [diff] [blame] | 19 | #pragma once |
| 20 | |
Harald Welte | 9d90d28 | 2018-06-29 22:25:42 +0200 | [diff] [blame] | 21 | #include <osmocom/core/linuxlist.h> |
Harald Welte | 119624f | 2017-11-04 12:28:30 +0100 | [diff] [blame] | 22 | #include "utils.h" |
Harald Welte | 9f240b6 | 2016-03-18 10:32:56 +0100 | [diff] [blame] | 23 | |
Harald Welte | 9ac794c | 2017-05-07 11:19:45 +0200 | [diff] [blame] | 24 | static inline void llist_add_irqsafe(struct llist_head *_new, |
| 25 | struct llist_head *head) |
| 26 | { |
Harald Welte | 119624f | 2017-11-04 12:28:30 +0100 | [diff] [blame] | 27 | unsigned long x; |
| 28 | |
| 29 | local_irq_save(x); |
Harald Welte | 9ac794c | 2017-05-07 11:19:45 +0200 | [diff] [blame] | 30 | llist_add(_new, head); |
Harald Welte | f231541 | 2017-11-28 19:16:10 +0100 | [diff] [blame] | 31 | local_irq_restore(x); |
Harald Welte | 9ac794c | 2017-05-07 11:19:45 +0200 | [diff] [blame] | 32 | } |
| 33 | |
Harald Welte | 9f240b6 | 2016-03-18 10:32:56 +0100 | [diff] [blame] | 34 | static inline void llist_add_tail_irqsafe(struct llist_head *_new, |
| 35 | struct llist_head *head) |
| 36 | { |
Harald Welte | 119624f | 2017-11-04 12:28:30 +0100 | [diff] [blame] | 37 | unsigned long x; |
| 38 | |
| 39 | local_irq_save(x); |
Harald Welte | 9f240b6 | 2016-03-18 10:32:56 +0100 | [diff] [blame] | 40 | llist_add_tail(_new, head); |
| 41 | __enable_irq(); |
| 42 | } |
| 43 | |
| 44 | static inline struct llist_head *llist_head_dequeue_irqsafe(struct llist_head *head) |
| 45 | { |
| 46 | struct llist_head *lh; |
Harald Welte | 119624f | 2017-11-04 12:28:30 +0100 | [diff] [blame] | 47 | unsigned long x; |
Harald Welte | 9f240b6 | 2016-03-18 10:32:56 +0100 | [diff] [blame] | 48 | |
Harald Welte | 119624f | 2017-11-04 12:28:30 +0100 | [diff] [blame] | 49 | local_irq_save(x); |
Harald Welte | 9f240b6 | 2016-03-18 10:32:56 +0100 | [diff] [blame] | 50 | if (llist_empty(head)) { |
| 51 | lh = NULL; |
| 52 | } else { |
| 53 | lh = head->next; |
| 54 | llist_del(lh); |
| 55 | } |
Harald Welte | 119624f | 2017-11-04 12:28:30 +0100 | [diff] [blame] | 56 | local_irq_restore(x); |
Harald Welte | 9f240b6 | 2016-03-18 10:32:56 +0100 | [diff] [blame] | 57 | |
| 58 | return lh; |
| 59 | } |