Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 15 | * |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | #ifndef thread_h |
| 21 | #define thread_h |
| 22 | |
Holger Hans Peter Freyther | cbf7d18 | 2010-07-31 05:25:35 +0800 | [diff] [blame] | 23 | #include <osmocore/linuxlist.h> |
| 24 | #include <osmocore/select.h> |
Holger Hans Peter Freyther | 97f66e2 | 2010-07-28 03:32:52 +0800 | [diff] [blame] | 25 | |
| 26 | #include <pthread.h> |
| 27 | |
| 28 | /** |
| 29 | * routines for dealing with threads |
| 30 | */ |
| 31 | struct thread_notifier { |
| 32 | struct bsc_fd bfd; |
| 33 | |
| 34 | int no_write; |
| 35 | int fd[2]; |
| 36 | |
| 37 | pthread_mutex_t guard; |
| 38 | struct llist_head *main_head; |
| 39 | struct llist_head *thread_head; |
| 40 | |
| 41 | struct llist_head __head1; |
| 42 | struct llist_head __head2; |
| 43 | }; |
| 44 | |
| 45 | struct thread_notifier *thread_notifier_alloc(); |
| 46 | |
| 47 | /** |
| 48 | * atomically swap two llist heads. This can be used |
| 49 | * to have two queues of data and then swap them for |
| 50 | * processing. |
| 51 | */ |
| 52 | void thread_swap(struct thread_notifier *); |
| 53 | |
| 54 | void thread_safe_add(struct thread_notifier *, struct llist_head *_new); |
| 55 | |
| 56 | void thread_init(void); |
| 57 | |
| 58 | #endif |