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