Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file write_queue.h |
| 2 | * Generic write queue implementation */ |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 3 | /* |
| 4 | * (C) 2010 by Holger Hans Peter Freyther |
| 5 | * (C) 2010 by On-Waves |
| 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 24 | #pragma once |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 25 | |
Harald Welte | 2777ecd | 2011-08-17 14:23:42 +0200 | [diff] [blame] | 26 | /*! \defgroup write_queue Osmocom msgb write queues |
| 27 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 28 | * \file write_queue.h */ |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 29 | |
Pablo Neira Ayuso | dc35dbe | 2011-03-28 19:24:20 +0200 | [diff] [blame] | 30 | #include <osmocom/core/select.h> |
| 31 | #include <osmocom/core/msgb.h> |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 32 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 33 | /*! write queue instance */ |
Pablo Neira Ayuso | 9111d93 | 2011-05-07 12:42:51 +0200 | [diff] [blame] | 34 | struct osmo_wqueue { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 35 | /*! osmocom file descriptor */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 36 | struct osmo_fd bfd; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 37 | /*! maximum length of write queue */ |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 38 | unsigned int max_length; |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 39 | /*! current length of write queue */ |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 40 | unsigned int current_length; |
| 41 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 42 | /*! actual linked list implementing the queue */ |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 43 | struct llist_head msg_queue; |
| 44 | |
Pau Espin Pedrol | 686eba9 | 2018-05-04 18:20:35 +0200 | [diff] [blame] | 45 | /*! call-back in case qeueue is readable. Return -EBADF if fd is freed inside cb. */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 46 | int (*read_cb)(struct osmo_fd *fd); |
Pau Espin Pedrol | 686eba9 | 2018-05-04 18:20:35 +0200 | [diff] [blame] | 47 | /*! call-back in case qeueue is writable. Return -EBADF if fd is freed inside cb. */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 48 | int (*write_cb)(struct osmo_fd *fd, struct msgb *msg); |
Pau Espin Pedrol | 686eba9 | 2018-05-04 18:20:35 +0200 | [diff] [blame] | 49 | /*! call-back in case qeueue has exceptions. Return -EBADF if fd is freed inside cb. */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 50 | int (*except_cb)(struct osmo_fd *fd); |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
Pablo Neira Ayuso | 9111d93 | 2011-05-07 12:42:51 +0200 | [diff] [blame] | 53 | void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length); |
| 54 | void osmo_wqueue_clear(struct osmo_wqueue *queue); |
| 55 | int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data); |
| 56 | int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what); |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 57 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 58 | /*! @} */ |