blob: 9171ccf462d98d9efbb337cd4b1a8d7f221740b9 [file] [log] [blame]
Kévin Redon9a12d682018-07-08 13:21:16 +02001/* 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 Welte9f240b62016-03-18 10:32:56 +010019#pragma once
20
Harald Welte9d90d282018-06-29 22:25:42 +020021#include <osmocom/core/linuxlist.h>
Harald Welte119624f2017-11-04 12:28:30 +010022#include "utils.h"
Harald Welte9f240b62016-03-18 10:32:56 +010023
Harald Welte9ac794c2017-05-07 11:19:45 +020024static inline void llist_add_irqsafe(struct llist_head *_new,
25 struct llist_head *head)
26{
Harald Welte119624f2017-11-04 12:28:30 +010027 unsigned long x;
28
29 local_irq_save(x);
Harald Welte9ac794c2017-05-07 11:19:45 +020030 llist_add(_new, head);
Harald Weltef2315412017-11-28 19:16:10 +010031 local_irq_restore(x);
Harald Welte9ac794c2017-05-07 11:19:45 +020032}
33
Harald Welte9f240b62016-03-18 10:32:56 +010034static inline void llist_add_tail_irqsafe(struct llist_head *_new,
35 struct llist_head *head)
36{
Harald Welte119624f2017-11-04 12:28:30 +010037 unsigned long x;
38
39 local_irq_save(x);
Harald Welte9f240b62016-03-18 10:32:56 +010040 llist_add_tail(_new, head);
41 __enable_irq();
42}
43
44static inline struct llist_head *llist_head_dequeue_irqsafe(struct llist_head *head)
45{
46 struct llist_head *lh;
Harald Welte119624f2017-11-04 12:28:30 +010047 unsigned long x;
Harald Welte9f240b62016-03-18 10:32:56 +010048
Harald Welte119624f2017-11-04 12:28:30 +010049 local_irq_save(x);
Harald Welte9f240b62016-03-18 10:32:56 +010050 if (llist_empty(head)) {
51 lh = NULL;
52 } else {
53 lh = head->next;
54 llist_del(lh);
55 }
Harald Welte119624f2017-11-04 12:28:30 +010056 local_irq_restore(x);
Harald Welte9f240b62016-03-18 10:32:56 +010057
58 return lh;
59}